Installing DRF
Installing and Configuring Django REST Framework
Django REST Framework (DRF) is the industry-standard toolkit for building Web APIs in Python. It equips Django with browsable web APIs, serializers, content negotiation, pagination, throttling, and modular authentication schemes. Configuring DRF correctly in settings.py establishes the architectural defaults for your entire API.
1. Installation
Add rest_framework to INSTALLED_APPS:
2. Global REST_FRAMEWORK Configuration
The REST_FRAMEWORK dictionary in settings.py defines global defaults across all endpoints:
3. The Interactive Browsable API
One of DRF's premier features is the Browsable API. When an endpoint is requested via a web browser (Accept: text/html), DRF renders a fully interactive HTML interface allowing developers to inspect JSON outputs, execute test POST / PUT forms, and view response headers directly in the browser!
To enable login/logout in the browsable API, include DRF's authentication views in urls.py:
4. Production Security: Disabling Browsable API
In high-security production environments, you may wish to disable the HTML Browsable API to save bandwidth and avoid exposing form schemas:
Practice Quiz
Serializers Overview
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Status Codes | Serializers Overview |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.