Installing Django REST Framework
In this page:
Installing the Package
With your virtual environment active, install DRF using pip, the same way you installed Django itself.
Note: Run this from your project's root folder, with the virtual environment activated.
Example: Installing the Package
With your virtual environment active, install DRF using pip, the same way you installed Django itself.
pip install djangorestframework
⚠️ Run this command in your terminal.
Registering the App
Like any Django app, DRF must be listed in INSTALLED_APPS so Django loads its templates, static files, and features (like the browsable API).
Example: Registering the App
Like any Django app, DRF must be listed in INSTALLED_APPS so Django loads its templates, static files, and features (like the browsable API).
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'myapp',
]
{# Django-only code -- models.py/views.py/urls.py/settings.py
snippets, or template markup using Django template tags/variables
-- can't run standalone via Judge0 or the browser preview, since
it needs a real Django project. Only this course's pure-Python
examples (example_lang == 'python', no Django imports) are
actually runnable, so those still get the button below. #}
Verifying the Install
Check that DRF installed correctly by confirming its version from the Python interpreter inside your virtual environment.
Example: Verifying the Install
Check that DRF installed correctly by confirming its version from the Python interpreter inside your virtual environment.
python -c "import rest_framework; print(rest_framework.VERSION)"
⚠️ Run this command in your terminal.
- Installing djangorestframework but forgetting to add rest_framework to INSTALLED_APPS, so DRF's features silently don't activate.
- Installing it globally instead of inside the project's virtual environment, causing version mismatches between machines.
- Not restarting the development server after adding rest_framework to settings.py.
- Install DRF into your active virtual environment with pip install djangorestframework.
- Add rest_framework to the INSTALLED_APPS list in settings.py.
- Restart the development server so the new app is picked up.
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: