{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":".promolia{float:left;width:130px;height:20px;text-align:center;margin:10px30px;padding:150px000;background-position:050%;background-size:130pxauto;background-repeat:no-repeat;font-size:120%;color:black;}.promoli{list-style:none;}DjangoRESTFrameworkDjangoRESTframeworkisapowerfulandflexibletoolkitforbuildingWebAPIs.SomereasonsyoumightwanttouseRESTframework:TheWebbrowsableAPIisahugeusabilitywinforyourdevelopers.AuthenticationpoliciesincludingpackagesforOAuth1aandOAuth2.SerializationthatsupportsbothORMandnon-ORMdatasources.Customizableallthewaydown-justuseregularfunction-basedviewsifyoudon'tneedthemorepowerfulfeatures.Extensivedocumentation,andgreatcommunitysupport.UsedandtrustedbyinternationallyrecognisedcompaniesincludingMozilla,RedHat,Heroku,andEventbrite.FundingRESTframeworkisacollaborativelyfundedproject.IfyouuseRESTframeworkcommerciallywestronglyencourageyoutoinvestinitscontinueddevelopmentbysigningupforapaidplan.Everysinglesign-uphelpsusmakeRESTframeworklong-termfinanciallysustainable.SentryStreamSpacinovRetoolbit.ioPostHogCryptAPIFEZTOSvixManythankstoallourwonderfulsponsors,andinparticulartoourpremiumbackers,Sentry,Stream,Spacinov,Retool,bit.io,PostHog,CryptAPI,FEZTO,andSvix.RequirementsRESTframeworkrequiresthefollowing:Django(4.2,5.0)Python(3.8,3.9,3.10,3.11,3.12)WehighlyrecommendandonlyofficiallysupportthelatestpatchreleaseofeachPythonandDjangoseries.Thefollowingpackagesareoptional:PyYAML,uritemplate(5.1+,3.0.0+)-Schemagenerationsupport.Markdown(3.3.0+)-MarkdownsupportforthebrowsableAPI.Pygments(2.7.0+)-AddsyntaxhighlightingtoMarkdownprocessing.django-filter(1.0.1+)-Filteringsupport.django-guardian(1.1.1+)-Objectlevelpermissionssupport.InstallationInstallusingpip,includinganyoptionalpackagesyouwant...pipinstalldjangorestframeworkpipinstallmarkdown#MarkdownsupportforthebrowsableAPI.pipinstalldjango-filter#Filteringsupport...orclonetheprojectfromgithub.gitclonehttps://github.com/encode/django-rest-framework Add 'rest_framework' to your INSTALLED_APPS setting. INSTALLED_APPS = [ ... 'rest_framework', ] If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py file. urlpatterns = [ ... path('api-auth/', include('rest_framework.urls')) ] Note that the URL path can be whatever you want. Example Let's take a look at a quick example of using REST framework to build a simple model-backed API. We'll create a read-write API for accessing information on the users of our project. Any global settings for a REST framework API are kept in a single configuration dictionary named REST_FRAMEWORK . Start off by adding the following to your settings.py module: 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' ] } Don't forget to make sure you've also added rest_framework to your INSTALLED_APPS . We're ready to create our API now. Here's our project's root urls.py module: from django.urls import path, include from django.contrib.auth.models import User 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 an easy way of automatically determining