Django REST Framework (DRF)

Django REST Framework (DRF) is the standard toolkit for building Web APIs on top of Django. It adds serializers, class-based API views and viewsets, authentication, permissions, and a browsable API for testing endpoints.

Django

Plain Django is built around HTML pages; DRF adds everything needed for JSON APIs. Its core pieces are serializers (convert between models and JSON, with validation), APIView and generic views, viewsets plus routers (which auto-generate URL routes for full CRUD), and pluggable authentication and permission classes.

A major productivity feature is the browsable API: DRF renders an interactive HTML interface for your endpoints in the browser, letting you read and submit data without a separate client during development. It also standardizes pagination, filtering, throttling, and content negotiation.

DRF is a third-party package you add to INSTALLED_APPS as 'rest_framework'. It is the de facto choice for REST APIs in Django; for GraphQL or async-first APIs, projects sometimes choose alternatives like Strawberry or Django Ninja.

Syntax

class PostViewSet(viewsets.ModelViewSet):
    queryset = Post.objects.all()

Examples

Python

from rest_framework import viewsets
from .models import Post
from .serializers import PostSerializer

class PostViewSet(viewsets.ModelViewSet):
    queryset = Post.objects.all()
    serializer_class = PostSerializer
# a router maps this to full CRUD endpoints

Learn it in a lesson

See also

Back to the Dictionary