Skip to content
Justice Tech School

ListView and DetailView

Generic views remove repeated code. ListView shows many objects and DetailView shows one. They guess the template name from the model.

Example
from django.views.generic import ListView, DetailView

class PostList(ListView):
    model = Post
    paginate_by = 10          # template: blog/post_list.html

class PostDetail(DetailView):
    model = Post              # template: blog/post_detail.html

path("", PostList.as_view()),
path("<int:pk>/", PostDetail.as_view()),

Exercise

View for many objects.

class PostList():

Quiz Test

What is the default context name in ListView?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.