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.SingleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.edit.BaseDeleteView
django.views.generic.edit.DeletionMixin
django.views.generic.detail.BaseDetailView
django.views.generic.detail.SingleObjectMixin
django.views.generic.base.View
Attributes
-
template_name_suffix
-
The
DeleteView
page displayed to aGET
request uses atemplate_name_suffix
of'_confirm_delete'
. For example, changing this attribute to'_check_delete'
for a view deleting objects for the exampleAuthor
model would cause the defaulttemplate_name
to be'myapp/author_check_delete.html'
.
Example myapp/views.py:
1 2 3 4 5 6 7 | 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:
1 2 3 4 | < 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.