Installation
Getting started with DRF is straightforward.
Prerequisites
- Python (3.6+)
- Django (3.0+)
Step-by-step Guide
Install using pip:
bashpip install djangorestframeworkAdd to
INSTALLED_APPS: Open your project'ssettings.pyand add'rest_framework'to your installed apps.pythonINSTALLED_APPS = [ ... 'rest_framework', ]Global Settings (Optional): You can configure global DRF settings in
settings.pyusing theREST_FRAMEWORKdictionary.pythonREST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' ] }
Optional Packages
None of these are required, but each adds a capability you are likely to want as an API grows:
bash
pip install markdown # Markdown support for the browsable API.
pip install django-filter # Filtering support.
pip install drf-spectacular # Schema generation support.
pip install djangorestframework-simplejwt # JSON Web Token authentication plugin for DRF.
pip install drf-writable-nested # Nested create and update support for serializers.