Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Python HTML Other
Latest commit 8dea1ae @tomchristie Merge pull request #3677 from Ernest0x/patch-4
Updated NestedBoundField to also handle empty string when rendering its form

Django REST framework

build-status-image coverage-status-image pypi-version

Awesome web-browsable Web APIs.

Full documentation for the project is available at

Note: We have now released Django REST framework 3.3. For older codebases you may want to refer to the version 2.4.4 source code, and documentation.

For more details see the 3.3 announcement and release notes.


Django REST framework is a powerful and flexible toolkit for building Web APIs.

Some reasons you might want to use REST framework:

There is a live example API for testing purposes, available here.

Below: Screenshot from the browsable API



  • Python (2.7, 3.2, 3.3, 3.4, 3.5)
  • Django (1.7, 1.8, 1.9)


Install using pip...

pip install djangorestframework

Add 'rest_framework' to your INSTALLED_APPS setting.



Let's take a look at a quick example of using REST framework to build a simple model-backed API for accessing users and groups.

Startup up a new project like so...

pip install django
pip install djangorestframework startproject example .
./ syncdb

Now edit the example/ module in your project:

from django.conf.urls import url, include
from django.contrib.auth.models import User
from rest_framework import serializers, viewsets, routers

# 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.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))

We'd also like to configure a couple of settings for our API.

Add the following to your module:

    ...  # Make sure to include the default installed apps here.

    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.

That's it, we're done!

./ runserver

You can now open the API in your browser at, and view your new 'users' API. If you use the Login control in the top right corner you'll also be able to add, create and delete users from the system.

You can also interact with the API using command line tools such as curl. For example, to list the users endpoint:

$ curl -H 'Accept: application/json; indent=4' -u admin:password
        "url": "",
        "username": "admin",
        "email": "",
        "is_staff": true,

Or to create a new user:

$ curl -X POST -d username=new -d -d is_staff=false -H 'Accept: application/json; indent=4' -u admin:password
    "url": "",
    "username": "new",
    "email": "",
    "is_staff": false,

Documentation & Support

Full documentation for the project is available at

For questions and support, use the REST framework discussion group, or #restframework on freenode IRC.

You may also want to follow the author on Twitter.


If you believe you’ve found something in Django REST framework which has security implications, please do not raise the issue in a public forum.

Send a description of the issue via email to The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.

Something went wrong with that request. Please try again.