Home › Django › Django Windsurf rules

Django Windsurf rules

Windsurf rules for Django 5.2 LTS projects: apps, models and migrations, ORM performance, forms, and tests.

WindsurfDjango

How to use

Save this as .windsurf/rules/django.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.windsurf/rules/django.mdDownload  
---
trigger: glob
globs: **/*.py,**/templates/**
---

# Django 5.2

- One Django app per domain area. Business logic in `services.py` functions or model methods, not in views or templates.
- Models: explicit `related_name`, `on_delete`, `Meta.ordering` only when needed, `constraints` (`UniqueConstraint`, `CheckConstraint`) instead of app-level checks. Use `db_default` for DB-side defaults.
- After model changes run `python manage.py makemigrations <app>` and review the file. Data migrations use `RunPython` with the historical model (`apps.get_model`).
- ORM performance: `select_related`/`prefetch_related` for related data, `only()`/`values()` for large reads, `bulk_create`/`update()` for batch writes, `F()` expressions for atomic updates. Avoid queries inside loops and templates.
- Class-based or function views, matching the app; protect them with `LoginRequiredMixin`/`@login_required` and permission checks.
- Forms (`ModelForm`) validate all user input; templates keep autoescape on and include `{% csrf_token %}`.
- Settings from env (django-environ or similar); `DEBUG=False` and `ALLOWED_HOSTS` in production.
- Async views only when the whole call chain is async (`aget`, `afilter`).

## Done when
`python manage.py check --deploy` (for settings changes), `makemigrations --check`, `ruff check .`, and the test suite (`pytest` or `manage.py test`) pass.

More: all Django rules · all Windsurf rules

Related rules

Django CLAUDE.md

CLAUDE.md for Django 5 projects with DRF, pytest-django and PostgreSQL.

Claude Code (CLAUDE.md)Django

Django REST Framework rules

Cursor rules for Django 5 + Django REST Framework APIs: serializers, viewsets, permissions, and query performance.

CursorDjango

FastAPI Windsurf rules

Windsurf rules for FastAPI apps with Pydantic v2, SQLAlchemy 2.0 async, dependency injection, and pytest.

WindsurfPython / FastAPI

Go + Gin web API Windsurf rules

Windsurf rules for Go 1.27 REST APIs built with Gin: handlers, binding/validation, middleware, and tests.

WindsurfGo

REST API design AGENTS.md

AGENTS.md for designing consistent HTTP/JSON APIs: resource naming, status codes, errors, pagination, and versioning.

AGENTS.mdAPI design

Bun runtime CLAUDE.md

CLAUDE.md for TypeScript projects on Bun 1.2+: bun test, Bun.serve, built-in SQLite/Postgres, and bundling.

Claude Code (CLAUDE.md)Bun

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.