【发布时间】:2020-04-21 07:23:28
【问题描述】:
我有一个表格来显示我的应用中的操作列表。我可以删除该表中的任何操作。所以,我在每一行都添加了一个删除按钮。此删除按钮将触发“删除确认”引导模式。
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" class="th-lg">Name</th>
</tr>
</thead>
{% for action in actions_list %}
<tbody>
<tr class="test">
<th scope="row" class="align-middle">{{ forloop.counter }}</th>
<td class="align-middle">
{{action.action_name}}
</td>
<td class="align-middle">
{{action.id}}
</td>
<td>
<div class="row justify-content-end">
<button
id="edit"
type="button"
class="btn btn-sm btn-dark col col-lg-2"
style="color: rgb(255,0,0,0)"
>
<i class="lni-pencil"></i>
</button>
<button
id="trash"
type="button"
class="btn btn-sm btn-dark col col-lg-2"
style="color: rgb(255,0,0,0)"
data-toggle="modal"
data-target="#modalConfirmDelete"
>
<i class="lni-trash"></i>
</button>
</div>
</td>
</tr>
</tbody>
{% endfor %}
</table>
以下是“删除确认”引导模式的代码。它将有“是”和“否”按钮。 如果我单击“是”,则该特定操作 ID 将被传递到 URL,并且该特定操作 ID 将被删除。
{% block modalcontent %}
<!--Modal: modalConfirmDelete-->
<div
class="modal fade"
id="modalConfirmDelete"
tabindex="-1"
role="dialog"
aria-labelledby="exampleModalLabel"
aria-hidden="true"
>
<div class="modal-dialog modal-sm modal-notify modal-danger" role="document">
<!--Content-->
<div class="modal-content text-center">
<!--Header-->
<div class="modal-header d-flex justify-content-center">
<p class="heading">Are you sure?</p>
</div>
<!--Body-->
<div class="modal-body">
<i class="fas fa-times fa-4x animated rotateIn"></i>
</div>
<!--Footer-->
<div class="modal-footer flex-center">
<form action="{% url 'delete_action' aid=action.id %}">
{% csrf_token %}
<button class="btn btn-outline-danger">Yes</button>
</form>
<a
type="button"
class="btn btn-danger waves-effect"
data-dismiss="modal"
>No</a
>
</div>
</div>
<!--/.Content-->
</div>
</div>
{% endblock %}
在上面的代码中,我使用 form 标记进行删除操作,然后该操作 id URL 将触发。
以下是删除操作的 URL,
re_path(r'^delete_action/(?P<aid>\d+)/',
views.delete_action, name='delete_action')
我面临的问题: 我需要我没有得到的模态中的 action.id 值!
请帮我解决这个问题。在此先感谢:)
【问题讨论】:
标签: python django django-templates bootstrap-modal jinja2