django-best-practices

django-best-practices is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (418 once invoked), scanned A, original, MIT.

A broad set of coding rules for Django projects, covering views, models, forms, databases, APIs, security, testing, and project structure. Django is a Python web framework.

In plain words
What is it for?
Use it when developing Django pages, forms, JSON APIs, authentication, database queries, error handling, static files, and automated tests.
Why use it?
It gives a consistent way to build and maintain Django code instead of making each part of the project follow different conventions.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when developing Django pages, forms, JSON APIs, authentication, database queries, error handling, static files, and automated tests.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/django-best-practices
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for django-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/django-best-practices/github.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/django-best-practices)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/django-best-practices"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/django-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for django-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/django-best-practices"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/django-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 418 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00418
Opus 5 $0.00000 $0.00209
Sonnet 5 $0.00000 $0.00084
Haiku 4.5 $0.00000 $0.00042

Measured 6d ago against content hash ec95f0147cc7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

django-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/backend/python/django/django-best-practices.mdc · 25 lines

What it actually says

  • 使用 Django 的类视图(CBV)处理复杂视图,简单逻辑可使用函数视图(FBV)
  • 数据库交互优先使用 ORM,除非出于性能需求避免编写原生 SQL
  • 采用 Django 内置 User 模型与认证框架管理用户
  • 使用 ModelForm / Form 处理表单与验证逻辑
  • 严格遵循 MVT(模型-视图-模板)模式,保持关注点分离
  • 合理使用 Middleware 处理跨切面需求,如认证、日志、缓存
  • 在视图层做异常捕获,并定制 404/500 等错误页面提升用户体验
  • 通过 Django Signals 解耦日志记录与错误处理
  • 使用 select_related / prefetch_related 优化关联查询性能
  • 利用缓存框架(Redis/Memcached)减少数据库压力
  • 使用 Celery 处理耗时后台任务,或编写异步视图应对 IO 密集型操作
  • 遵循 PEP 8 命名与代码风格,提高可读性与可维护性
  • 将业务逻辑拆分到独立 App,保持项目结构模块化
  • 使用 Django REST Framework Serializer 构建 JSON API
  • 在 urls.py 中定义清晰的 RESTful 路由
  • 启用 CSRF、防 SQL 注入、防 XSS 等安全机制,定期审计安全配置
  • 使用 unittest/pytest-django 编写单元与集成测试确保质量
  • 通过 WhiteNoise 或 CDN 优化静态文件服务
  • 为关键字段添加数据库索引,监控并优化慢查询
  • 遵循“约定优于配置”原则,减少样板代码并保持一致性
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 25 lines · 0 tokens per session scan A ec95f0147cc7

Subscribe to this mod's changes

django-best-practices is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (233 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 418 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.