← Back to Django Course | Chapter 14: REST API with DRF | Lesson 2 of 6

Installing Django REST Framework

Before you can build a JSON API, you install the djangorestframework package and tell Django to use it.

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.

bash
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).

markup
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.

bash
python -c "import rest_framework; print(rest_framework.VERSION)"

⚠️ Run this command in your terminal.

Common Mistakes
  1. Installing djangorestframework but forgetting to add rest_framework to INSTALLED_APPS, so DRF's features silently don't activate.
  2. Installing it globally instead of inside the project's virtual environment, causing version mismatches between machines.
  3. Not restarting the development server after adding rest_framework to settings.py.
Chapter Summary
  • 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.