Check the current Django release notes and supported versions before starting; use a supported LTS release for long-lived projects.
Layout
Section titled “Layout”- One Django app per domain area (
orders,accounts,catalog), each with its models, services, views, serializers, admin and tests. - Business logic in plain service functions or modules, not in views or model
save()overrides. - Settings split by environment or driven entirely by environment variables (
django-environor similar);.env.examplecommitted.
Security settings (production)
Section titled “Security settings (production)”DEBUG = False;ALLOWED_HOSTSandCSRF_TRUSTED_ORIGINSexplicit.SECURE_SSL_REDIRECT,SESSION_COOKIE_SECURE,CSRF_COOKIE_SECURE,SECURE_HSTS_SECONDSset;SECURE_CONTENT_TYPE_NOSNIFFon.SECRET_KEYfrom the environment, unique per environment.- Run
python manage.py check --deployin CI for production settings and fix every warning or document why. - Never use
|safe,mark_safeor raw SQL with user input without review.
- Migrations committed and reviewed; never edit an applied migration.
- Use
select_related/prefetch_relatedto avoid N+1 queries; add indexes inMeta.indexes. - Money in
DecimalField; timestamps timezone-aware (USE_TZ = True). - Use database constraints (
UniqueConstraint,CheckConstraint).
- Django REST Framework (or Django Ninja) with serializers validating all input, explicit permission classes on every view (deny by default), pagination on every list, throttling on auth and expensive endpoints.
- Generate an OpenAPI schema and keep it in the repo.
Background work
Section titled “Background work”- Celery, RQ or Django’s task framework (check availability in your version) for email, file processing and LLM calls; tasks idempotent with retries.
Quality
Section titled “Quality”pytestwithpytest-django; factories for test data; no real personal data.- Ruff for lint and format; mypy or pyright with
django-stubs. pip-auditor similar in CI; dependencies pinned with hashes.
Deployment
Section titled “Deployment”- Gunicorn or Uvicorn behind a reverse proxy; static files via WhiteNoise or a CDN.
migrateas an explicit release step; health-check endpoint; structured logging to stdout.
Checklist
Section titled “Checklist”- Apps by domain; logic in services
-
check --deployclean - Permissions on every view; pagination; throttling
- Migrations reviewed; N+1 avoided
- pytest, ruff, type checker, audit in CI