ListView and DetailView
Display collections and single records.
ListView and DetailView is a free Django Academy lesson on CoddyKit — lesson 1 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.
Two Pages You Always Need
Nearly every app shows a list of things and a page for one thing. Django ships generic views that build both for you. ✨
Meet ListView
ListView fetches many objects and hands them to a template, so you skip writing the query and the render call yourself.
Point ListView at a Model
You give ListView a model, and it runs the query for every row in that table automatically.
from django.views.generic import ListView
from .models import Post
class PostList(ListView):
model = PostThe Default Template Name
ListView looks for a template named app/model_list.html, like post_list.html, unless you override it.
object_list in the Template
Inside the template the rows arrive as object_list, ready for you to loop over and display.
{% for post in object_list %}
<li>{{ post.title }}</li>
{% endfor %}Nicer Names with context_object_name
Set context_object_name so your template variable reads naturally, like posts instead of object_list.
class PostList(ListView):
model = Post
context_object_name = "posts"Meet DetailView
DetailView fetches a single object by its key and renders one focused page for it.
How DetailView Finds the Object
DetailView reads a pk or slug from the URL, then runs get() to load exactly that one record.
from django.views.generic import DetailView
class PostDetail(DetailView):
model = PostThe Detail Template and object
DetailView renders app/model_detail.html and exposes the record as object in the template.
<h1>{{ object.title }}</h1>
<p>{{ object.body }}</p>Wiring Them into URLs
Each generic view becomes a URL with as_view(), which turns the class into a callable view.
path("posts/", PostList.as_view()),
path("posts/<int:pk>/", PostDetail.as_view()),Less Code, Same Result
Together these two views replace dozens of lines of boilerplate, giving you list and detail pages almost for free. 🚀
Quick Check
Where does DetailView get the object it shows?
Recap: List and Detail
You met ListView for collections and DetailView for one record, wired both with as_view(), and skipped tons of boilerplate. 🎉
Frequently asked questions
Is the “ListView and DetailView” lesson free?
Yes — the full text of “ListView and DetailView” 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 “ListView and DetailView”?
Display collections and single records. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “ListView and DetailView” 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
- ListView and DetailView
- CreateView and UpdateView
- DeleteView and success_url
- Overriding get_queryset and Templates