Django Cursor Rules Template
Generate production-ready Django Cursor rules for Project Rules (.mdc), AGENTS.md, or legacy .cursorrules. This template encodes stack-specific conventions for projects using Django. Python web framework with ORM, admin, auth, and batteries-included conventions.
The Complete Django Cursor Rules
The full rule set in all three formats Cursor understands — copy the one your project uses. Project Rules (.mdc) load per-file via globs, AGENTS.md is portable across AI tools, and .cursorrules is the legacy single-file format.
Replacing a legacy file? Read the guide to migrate .cursorrules to Cursor Project Rules (.mdc) before copying this template into your project.
---
description: "Project Structure"
alwaysApply: false
---
- Follow Django's app-based modular structure.
- Use spaces for indentation.
- Use snake_case for variables, functions, and methods.
- Keep business logic in models, managers, and services — not in views.
- Use class-based views for common patterns, function-based for simple ones.
- Organize templates by app under templates/<app_name>/.---
description: "Models & ORM"
alwaysApply: false
---
- Define models with explicit field types and constraints.
- Use Meta class for ordering, indexes, and constraints.
- Use related_name explicitly for ForeignKey and ManyToManyField.
- Use model managers for reusable queryset logic.
- Use select_related() and prefetch_related() to avoid N+1 queries.
- Use migrations for all schema changes — never alter tables manually.---
description: "Views & APIs"
alwaysApply: false
---
- Use Django REST Framework for API endpoints.
- Use ModelSerializer for CRUD serializers.
- Use ViewSets with routers for standard REST patterns.
- Use permission_classes for access control on every endpoint.
- Use @action decorator for custom non-CRUD endpoints.
- Use pagination for list endpoints with reasonable defaults.---
description: "Testing"
alwaysApply: false
---
- Use pytest-django for test discovery and fixtures.
- Use Django's TestCase or APITestCase for integration tests.
- Use factory_boy or model_bakery for test data generation.
- Test models, views, and serializers independently.
- Use transactional tests (TestCase wraps in a transaction).
- Mock external services — don't hit real APIs in tests.Customize These Rules
The generator below is preloaded with the Django template. Adjust indentation, quotes, naming, add your own rules, then download — no need to start from scratch on the homepage.
What This Template Covers
Required guidance
- - Project Structure
- - Models & ORM
- - Views & APIs
- - Testing
Default style
- - Indentation: 4 spaces
- - Quotes: double
- - Semicolons: disabled
- - Naming: snake_case
Frequently Asked Questions
- What does the Django Cursor rules template include?
- It includes 4 rule sections covering project structure, models & orm, views & apis and other Django development conventions.
- Can I generate Django Project Rules and AGENTS.md from the same template?
- Yes. The generator can export the same stack-specific guidance as modern Project Rules (.mdc), AGENTS.md, or a legacy .cursorrules file.
- Should I combine Django with other Cursor rules templates?
- Yes. You can combine Django with related templates such as TypeScript, Tailwind CSS, Docker, or backend frameworks when your project uses multiple technologies.