Skip to main content

Django REST Framework

A powerful and flexible toolkit for building Web APIs

Overview

Django REST Framework is a powerful and flexible toolkit for building Web APIs with Django. It provides a comprehensive set of tools that make it easy to build RESTful APIs quickly and efficiently.

Quick Start

Get started with Django REST Framework in minutes

Tutorial

Learn through our comprehensive step-by-step tutorial

API Reference

Explore the complete API documentation

Community

Join the community and find resources

Why Django REST Framework?

The web browsable API is a huge usability win for your developers. It provides an interactive interface for exploring and testing your API endpoints directly in the browser.
Comprehensive serialization system that supports both ORM and non-ORM data sources. Convert complex data types like Django model instances to native Python datatypes that can be easily rendered into JSON, XML, or other content types.
Flexible authentication including packages for OAuth1a and OAuth2. Granular permission controls to ensure your API is secure and accessible only to authorized users.
Use regular function-based views if you don’t need the more powerful features. The framework is designed to be customizable at every level, from serializers to views to routers.

Key Features

  • Powerful serialization system supporting both ORM and non-ORM data sources
  • Class-based and function-based views with generic views and viewsets
  • Automatic URL routing with routers
  • Flexible authentication including session, token, and OAuth support
  • Granular permission controls for fine-grained access management
  • Built-in pagination, filtering, and throttling for production-ready APIs
  • Web browsable API for easy debugging and exploration
  • Multiple renderer support including JSON, XML, YAML, and more
  • Comprehensive content negotiation for handling different client requirements
  • Extensive validation and error handling for robust API development

Requirements

Django REST Framework requires Python 3.10+ and Django 4.2+
We highly recommend and only officially support the latest patch release of each Python and Django series:
  • Python: 3.10, 3.11, 3.12, 3.13, 3.14
  • Django: 4.2, 5.0, 5.1, 5.2, 6.0

Installation

Install Django REST Framework using pip:
pip install djangorestframework
Add rest_framework to your INSTALLED_APPS setting:
settings.py
INSTALLED_APPS = [
    # ...
    'rest_framework',
]

Example

Here’s a quick example of using REST framework to build a simple model-backed API:
urls.py
from django.contrib.auth.models import User
from django.urls import include, path
from rest_framework import routers, serializers, viewsets


# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ['url', 'username', 'email', 'is_staff']


# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer


# Routers provide a way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)

# Wire up our API using automatic URL routing.
urlpatterns = [
    path('', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]
Configure your API settings in settings.py:
settings.py
REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
    ]
}
That’s it! You now have a fully functional API. Run your development server:
python manage.py runserver
You can now open the API in your browser at http://127.0.0.1:8000/ and view your new users API.

Next Steps

Installation Guide

Detailed installation and configuration instructions

Quickstart Tutorial

Build your first API in minutes

Step-by-Step Tutorial

Complete tutorial series covering all major features

API Reference

Comprehensive API documentation

Community & Support

GitHub

Star us on GitHub and contribute

Discussion Group

Ask questions and get help

Security Policy

Report security vulnerabilities

Build docs developers (and LLMs) love