【问题标题】:How to create a confirmation popup for class.DeleteView如何为 class.DeleteView 创建确认弹出窗口
【发布时间】:2018-02-10 12:37:19
【问题描述】:

我希望在单击删除按钮时创建一个确认弹出窗口。它目前可以正常工作并立即删除。这是我的一些代码: 视图.py:

class patientDelete(LoginRequiredMixin, DeleteView):
    model = patient
    success_url = reverse_lazy('patients:index')

index.html

<form action="{% url 'patients:patient-delete' patient.id %}" method="post" style="display: inline;">
    {% csrf_token %}
    <input type="hidden" name="patient_id" value="{{ patient.id }}" />
    <button type="submit" class="btn btn-default btn-sm">
        <span class="glyphicon glyphicon-trash"></span>
    </button>
</form>

还有我的 urls.py

# /patients/patient/pk/delete
url(r'patient/(?P<pk>[0-9]+)/delete/$', views.patientDelete.as_view(), name='patient-delete'),

我已经搜索了左、右和中心,但并没有真正理解其中的大部分内容。我在这里使用了很多教程来帮助我,并且对 django 很陌生。提前感谢您的帮助!

【问题讨论】:

    标签: python django popup


    【解决方案1】:

    您可以在&lt;button&gt;onclick 属性中使用javascript confirm 方法:

    <button type="submit" class="..." onclick="return confirm('Are you sure?');">
    

    您可以阅读更多关于returnonclick 中的工作原理here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2014-05-26
      • 1970-01-01
      • 2021-10-07
      相关资源
      最近更新 更多