class django.views.generic.edit.DeleteView
A view that displays a confirmation page and deletes an existing object. The given object will only be deleted if the request method is POST. If this view is fetched via GET, it will display a confirmation page that should contain a form that POSTs to the same URL.
Ancestors (MRO)
This view inherits methods and attributes from the following views:
django.views.generic.detail.SingleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.edit.BaseDeleteViewdjango.views.generic.edit.DeletionMixindjango.views.generic.detail.BaseDetailViewdjango.views.generic.detail.SingleObjectMixindjango.views.generic.base.View
Attributes
-
template_name_suffix -
The
DeleteViewpage displayed to aGETrequest uses atemplate_name_suffixof'_confirm_delete'. For example, changing this attribute to'_check_delete'for a view deleting objects for the exampleAuthormodel would cause the defaulttemplate_nameto be'myapp/author_check_delete.html'.
Example myapp/views.py:
from django.views.generic.edit import DeleteView
from django.urls import reverse_lazy
from myapp.models import Author
class AuthorDelete(DeleteView):
model = Author
success_url = reverse_lazy('author-list')
Example myapp/author_confirm_delete.html:
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm" />
</form>
Please login to continue.