Web APIs for Django. 🎸
Awesome web-browsable Web APIs.
Full documentation for the project is available at https://www.django-rest-framework.org/.
Django REST framework is a powerful and flexible toolkit for building Web APIs.
Some reasons you might want to use REST framework:
Below: Screenshot from the browsable API

We highly recommend and only officially support the latest patch release of each Python and Django series.
Install using pip...
pip install djangorestframeworkAdd 'rest_framework' to your INSTALLED_APPS setting.
INSTALLED_APPS = [
# ...
"rest_framework",
]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.
Start up a new project like so...
pip install django
pip install djangorestframework
django-admin startproject example .
./manage.py migrate
./manage.py createsuperuserNow edit the example/urls.py module in your project:
…We'd also like to configure a couple of settings for our API.
Add the following to your settings.py module:
INSTALLED_APPS = [
# ... make sure to include the default installed apps here.
"rest_framework",
]
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, we're done!
./manage.py runserverYou can now open the API in your browser at http://127.0.0.1:8000/, 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 http://127.0.0.1:8000/users/
[
{
"url": "http://127.0.0.1:8000/users/1/",
"username": "admin",
"email": "[email protected]",
"is_staff": true,
}
]Or to create a new user:
$ curl -X POST -d username=new -d [email protected] -d is_staff=false -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/
{
"url": "http://127.0.0.1:8000/users/2/",
"username": "new",
"email": "[email protected]",
"is_staff": false,
}Full documentation for the project is available at https://www.django-rest-framework.org/.
For questions and support, use the REST framework discussion group, or #restframework on libera.chat IRC.
Please see the security policy.
Invalid `self.instance` when validating the serializer using `many=True`
Not possible to override serializer_field_mappings with a field that has choices (for example a from ChoiceField derived field)
"No POST data" in error report
ModelSerializer uniqueness check crashes with OverflowError and that crash can not be prevented with field-level validation
Model unique_for_month changes ability to partially update ModelSerializer
Document that explicitly declared fields will not have their attributes overridden by `read_only_fields` shortcut.
a viewset's action list gets "head" added to it, but only after being called at least once
`required: True` set on a nullable field which is included in combined_unique
TemplateHTMLRenderer - TypeError - context must be a dict rather than ReturnList.
Partial updates and object-level validations