如何创建class.DeleteView的确认弹出窗口

问题描述:

每当单击删除按钮时,我正在创建一个确认弹出窗口。它目前是功能性的,并立即删除。下面是我的一些代码: views.py:如何创建class.DeleteView的确认弹出窗口

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来说是相当新的。感谢您的帮助!

您可以使用JavaScript confirm方法您<button>onclick属性中:

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

你可以阅读更多关于returnonclick如何工作here