django

Django Defaults

Core Django patterns and conventions

Python
framework
Used by 526 projects

Details

Language / Topic
pythonPython
Category
framework
Compatible Frameworks
django

Rules

balanced
- Organize projects into feature-based Django apps, each containing models.py, views.py, urls.py, and admin.py.
- Define all ORM models in a single models.py file per app.
- Route URLs via app-specific urls.py included in the root urls.py.
- Implement CLI functionality using custom management commands in app/management/commands/.
- Define models with explicit field types: `name = models.CharField(max_length=200)` — add `db_index=True` on fields used in filters.
- Use class-based views (`ListView`, `CreateView`, `DetailView`) for CRUD — override `get_queryset()` for filtered results.
- Use `select_related('fk_field')` and `prefetch_related('m2m_field')` in querysets to eliminate N+1 queries.
- Configure URL patterns in `urls.py` with `path('users/<int:pk>/', UserDetailView.as_view())` — use `include()` for app-level routing.