Appearance
Django Rest Framework - Tips and Checklists
Tips
- the best way to clear data is by sending an empty list or value, if the field allows writing this will be handled by the serializer
- when setting variables consider the possible size of the variable being stored, large objects being set to variables can cause issues with memory
- use
JSONFieldoverDictField - delete endpoints should return a 200 or no content
Schemas and Documentation
- Schema: is a machine readable document that outlines all available API endpoints, URLs and HTTP verbs (post, put, etc)
- schemas default to the
OpenAPIspecsdrf-spectactularis the recommended third party package to generate OpenAPI 3 schema for DRF- can make use of
SpectacularAPIViewto create a URL for viewing the schema as a part of the API
- can make use of
- schemas default to the
- Documentation: added to a schema to make it easier for humans to read and consume
- two popular options are
RedocandSwaggerUISwaggerUIis as straightforward asdrf-spectacular
- two popular options are
Deployment Checklist
- add environment variables via
environs[django] - set
DEBUGtoFalse - set
ALLOWED_HOSTS - use environment variable for
SECRET_KEY - update
DATABASESto use SQLite locally and PostgreSQL in production - configure static files and install
whitenoise - install
gunicornfor a production web server - create a
requirements.txtfile - create a
Procfilefor Heroku - create a
runtime.txtto set the Python version on Heroku
