From Classy Class Based Views DeleteView

View for deleting an object retrieved with self.get*object(), with a *

response rendered by a template.


There are no new attributes, but 2 that we’ve seen are required: (1) queryset or model; and (2) success_url


class myDeleteView(DeleteView):
    queryset = Person.objects.all()
    success_url = reverse_lazy('rango:list_view')

path('delete_view/<int:pk>', views.myDeleteView.as_view(), name='delete_view'),


Below is just the form that would be needed to get the delete to work.

    <form method="post">
    {% csrf_token %}
    <table border="1">
        <th>First Name</th>
        <th>Last Name</th>
            <td>{{ person.first_name }}</td>
            <td>{{ person.last_name }}</td>
        <a href="{% url 'rango:list_view' %}">Back</a>
        <input type="submit" value="Delete">


A visual representation of how DeleteView is derived can be seen here:



As far as implementations, the ability to add a form to delete data is about the easiest thing you can do in Django. It requires next to nothing in terms of implementing. We now have step 4 of a CRUD app!