0Pricing
Django Academy · Lesson

DeleteView and success_url

Confirm deletions and redirect afterward.

DeleteView and success_url is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Removing Records Safely

Sometimes data has to go. DeleteView handles removing a record, with a confirmation step built in. 🗑️

Meet DeleteView

DeleteView loads one object by its pk and prepares to delete it once the user confirms.

from django.views.generic import DeleteView

class PostDelete(DeleteView):
    model = Post

Why Confirmation Matters

Deleting is permanent, so DeleteView shows a confirmation page on GET before anything is removed.

The Confirm Template

By default DeleteView looks for app/model_confirm_delete.html, like post_confirm_delete.html.

The Confirmation Form

The confirm page posts back to the same URL, and that POST request is what actually triggers the delete.

<form method="post">{% csrf_token %}
  <p>Delete {{ object }}?</p>
  <button>Yes, delete</button>
</form>

Where success_url Comes In

After deleting, the user needs somewhere to go. success_url sets that destination explicitly.

from django.urls import reverse_lazy

class PostDelete(DeleteView):
    model = Post
    success_url = reverse_lazy("post_list")

Why reverse_lazy Here

Use reverse_lazy, not reverse, because URLs are not ready when the class body is first read at import time.

reverse vs reverse_lazy

reverse resolves a URL immediately, while reverse_lazy waits until the value is actually needed.

Wiring the Delete URL

The delete URL captures a pk so DeleteView knows which record to remove.

path("<int:pk>/delete/", PostDelete.as_view()),

Linking to Delete

From a detail page, link to delete using the url tag and the object pk so the right record is targeted.

<a href="{% url 'post_delete' object.pk %}">Delete</a>

Safe by Design

The GET confirm plus POST delete pattern means no record vanishes from a stray click or a crawler. ✅

Quick Check

What does success_url control in a DeleteView?

Recap: Deleting Records

You used DeleteView with a GET confirm and POST delete, then sent users onward with success_url and reverse_lazy. 🎉

Frequently asked questions

Is the “DeleteView and success_url” lesson free?

Yes — the full text of “DeleteView and success_url” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “DeleteView and success_url”?

Confirm deletions and redirect afterward. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “DeleteView and success_url” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. ListView and DetailView
  2. CreateView and UpdateView
  3. DeleteView and success_url
  4. Overriding get_queryset and Templates
← Back to Django Academy