Skip to content

@tank/python-django

1.0.0

Description

Production Django patterns covering models, ORM optimization, views, templates, DRF, Django Ninja, HTMX, Celery, testing, migrations, caching, and deployment.

Triggered by

djangodrfdjango ormdjango htmxdjango celerydjango ninja
Download
Verified
tank install @tank/python-django

Python Django

Core Philosophy

  1. Use Django conventions first — The framework already solves most web-application structure problems well. Override conventions only when there is clear value.
  2. Treat the ORM as a query builder, not magic — Know when select_related, prefetch_related, annotations, and transactions matter.
  3. Keep views thin and workflows explicit — Move heavy orchestration into services, tasks, or domain helpers when complexity grows.
  4. Server-rendered and API paths can coexist — Django is strong at HTML, JSON, and mixed architectures when boundaries stay clear.
  5. Operational discipline matters — Migrations, Celery, caching, and deployment decisions shape reliability as much as application code.

Quick-Start: Common Problems

"My Django pages are slow"

  1. Inspect query count first
  2. Add select_related for foreign-key joins
  3. Add prefetch_related for collections
  4. Avoid template-level hidden ORM work -> See references/models-and-orm.md

"Should I use CBVs or FBVs?"

NeedUse
straightforward request flowFBV
repeated CRUD/list/detail patternsCBV
REST APIsDRF views/viewsets as appropriate
-> See references/views-and-routing.md

"How do I add async/background work?"

  1. Keep request path synchronous only for user-critical work
  2. Push email/webhooks/reporting to Celery
  3. Make tasks idempotent when possible -> See references/operations-and-deployment.md

Decision Trees

Surface Selection

SignalRecommendation
mostly server-rendered appDjango templates/forms
API-first backendDRF or Django Ninja
progressively enhanced HTML interactionsHTMX + Django
mixed app + APIkeep boundaries explicit

Query Optimization Choice

SignalUse
one-to-one / foreign key joinselect_related
many-to-many or reverse relationprefetch_related
aggregate values neededannotations / aggregation

Reference Index

FileContents
references/models-and-orm.mdModels, QuerySets, relations, select_related, prefetch_related, annotations, migrations, managers
references/views-and-routing.mdFBVs, CBVs, URL routing, forms, middleware, auth boundaries, request/response structure
references/apis-and-htmx.mdDRF, serializers, viewsets, permissions, Django Ninja, HTMX integration, mixed app/API patterns
references/testing-and-auth.mdDjango testing, DRF testing, auth flows, permissions, factories, fixtures, request testing
references/operations-and-deployment.mdCelery, caching, static/media, deployment, environment config, production operations

Command Palette

Search skills, docs, and navigate Tank