Django + Python Rules
Python web application with Django and best practices
# 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
# Code 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.
# Code 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.
# What to 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 Django + Python AI Rules
AI coding rules files help your AI assistant (Cursor, Windsurf, Claude Code, GitHub Copilot, or Cline) understand your 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 is designed for Django + Python projects and 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.
Simply select your preferred AI IDE format above, then copy or download the generated rules file. Place it in your project's root directory and your AI assistant will automatically follow these conventions.
Get This Preset for a Specific IDE
Cursor
Django + Python rules for Cursor
Windsurf
Django + Python rules for Windsurf
Claude Code
Django + Python rules for Claude Code
GitHub Copilot
Django + Python rules for GitHub Copilot
Cline
Django + Python rules for Cline
Zed AI
Django + Python rules for Zed AI
Aider
Django + Python rules for Aider
Continue.dev
Django + Python rules for Continue.dev
Devin AI
Django + Python rules for Devin AI
Amazon Q
Django + Python rules for Amazon Q
Bolt.new
Django + Python rules for Bolt.new
Lovable
Django + Python rules for Lovable
Replit AI
Django + Python rules for Replit AI
Augment Code
Django + Python rules for Augment Code
JetBrains AI
Django + Python rules for JetBrains AI