~/TechPurAI
~/tutorials/django-rest-framework/generic-views
intermediate·part 8 of 22·2 min read

Generic views: ListCreateAPIView and RetrieveUpdateDestroyAPIView

Updated Aug 16, 2026Python · Django

TaskListView and TaskDetailView from part 7 both follow a pattern DRF has already automated: query a model, serialize it, handle the standard CRUD operations. Generic views are that automation — the same relationship ListView/DetailView have to a plain Django view, applied to an API.

ListCreateAPIView

python
# tasks/views.py
from rest_framework.generics import ListCreateAPIView
from .models import Task
from .serializers import TaskSerializer

class TaskListView(ListCreateAPIView):
    queryset = Task.objects.all()
    serializer_class = TaskSerializer

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

ListCreateAPIView handles GET (list) and POST (create) with queryset and serializer_class as the only two things to declare — the exact get()/post() methods written by hand in part 7 are gone. perform_create() is the hook for anything that needs to happen alongside saving a valid object — here, setting owner, the same job form_valid() did for CreateView in the Django from scratch series.

RetrieveUpdateDestroyAPIView

python
from rest_framework.generics import RetrieveUpdateDestroyAPIView

class TaskDetailView(RetrieveUpdateDestroyAPIView):
    queryset = Task.objects.all()
    serializer_class = TaskSerializer

This one class replaces every method TaskDetailView had in part 7 — GET (retrieve), PUT/PATCH (update), and DELETE (destroy) — with zero method bodies of your own. The URLconf from part 7 doesn't need to change at all; both classes still get wired up with .as_view() exactly the same way.

The generic view family

Each name directly describes which operations it supports — picking the narrowest one that fits a given endpoint is itself a form of access control: a ListAPIView for a read-only public endpoint makes an accidental POST handler structurally impossible, not just unwritten.

Common mistake

Reaching for the full RetrieveUpdateDestroyAPIView out of habit on an endpoint that should only ever be read from. Using the narrower RetrieveAPIView instead isn't just cleaner — it means there's no update/destroy method sitting there to accidentally get exposed later by a permissions misconfiguration (part 16).

Generic views remove boilerplate for the common case — but "list every task" and "list one user's tasks" are still two different classes with copy-pasted queryset/serializer_class. Next: ViewSet, which collapses an entire resource's list-detail-create-update-delete into one class.

VK

Vijay Kumar

Founder of TechPurAI — writing hands-on tutorials and honest tool breakdowns.

LinkedIn ↗
← previous7. Class-based views: APIViewnext →9. ViewSets: collapsing a resource's views into one class