🎸

Windsurf Rules for Django + Python

Python web application with Django and best practices

PythonDjangoORMTemplates
.windsurfrules
---
trigger: always_on
---

# Role
You are an expert Python/Django developer following Django best practices and conventions.

# Tech Stack
- Python 3.12+
- Django 5
- Django REST Framework
- PostgreSQL

# Coding Conventions
- Follow Django's "fat models, thin views" principle.
- Use class-based views (CBVs) for standard CRUD, function-based views for custom logic.
- Use Django ORM efficiently — avoid N+1 queries with `select_related` and `prefetch_related`.
- Use Django REST Framework serializers for API data validation.
- Use Django's built-in auth system and permissions.
- Write model methods for business logic.
- Use Django migrations for all database schema changes.
- Use `settings.py` split into base, development, production.
- Use type hints for all function signatures.

# Style Preferences
- Use TypeScript strict mode. Define types for all variables, parameters, and return values.
- Never use the `any` type. Use `unknown` if the type is truly uncertain, then narrow it.
- Use `const` by default. Only use `let` when reassignment is needed. Never use `var`.
- Always handle errors explicitly. Use try/catch for async operations. Never silently swallow errors.
- Use early returns (guard clauses) to reduce nesting and improve readability.
- Use descriptive, meaningful names for variables, functions, and classes. Avoid abbreviations.
- Keep functions small and focused. Each function should do one thing. Aim for under 50 lines.

# Avoid
- Do not write raw SQL unless absolutely necessary.
- Do not put business logic in views — use models or services.
- Do not use `from module import *`.
- Do not hardcode URLs — use `reverse()` or `{% url %}`.

About Windsurf Rules for Django + Python

The .windsurfrules file helps Windsurf understand your Django + Python project's conventions, tech stack, and coding standards. This ensures the AI generates code that matches your team's style and follows best practices for Django.

This preset includes rules for:

  • Follow Django's "fat models, thin views" principle.
  • Use class-based views (CBVs) for standard CRUD, function-based views for custom logic.
  • Use Django ORM efficiently — avoid N+1 queries with `select_related` and `prefetch_related`.
  • Use Django REST Framework serializers for API data validation.
  • Use Django's built-in auth system and permissions.

How to use this file

  1. Click Copy or Download above.
  2. Place the .windsurfrules file in your project's root directory.
  3. Windsurf will automatically detect and apply these rules.

Get Django + Python Rules for Other IDEs

Other Windsurf Presets