
Cursor with Django: .cursorrules that keep it idiomatic
Django has strong opinions about how things should be done. Fat models, thin views, class-based vs function-based views, the ORM, forms — there's a right way that the community has settled on. Without guidance, Cursor sometimes drifts toward generic Python patterns that ignore Django conventions. Here's the .cursorrules setup for Django projects. The core file # Django project rules ## Stack Django 5.x, Python 3.11+, PostgreSQL, Django REST Framework for APIs ## Project structure (standard Django) - myapp/ — main application (models, views, urls, admin) - myapp/services/ — business logic (not in views or models) - myapp/api/ — DRF serializers, viewsets, API urls - myapp/tests/ — test modules (not tests.py at root) - config/ — settings, urls, wsgi, asgi ## Models - Business logic belongs in model methods or service classes, not views - Use model managers for complex querysets - Use select_related() and prefetch_related() to avoid N+1 queries - Migrations: always generate with makemigrat
Continue reading on Dev.to Python
Opens in a new tab



