You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copies of all generated agent guidelines, with relevant excerpts in this README.
OpenAI Codex
PRs target main and fill .github/pull_request_template.md: include ticket number (or N/A), branch description, AI assistance disclosure, and checklist items.
Warp
The .github/pull_request_template.md file wasn’t detected.
Claude Code
AI-Assisted Contributions
When using AI tools (including Claude Code):
You must disclose AI tool usage in the PR template
You must fully review and verify all AI-generated output
Ensure code aligns with Django's architecture and passes the full test suite
Unverified AI contributions may be closed without review
Mistral Vibe
Agent Contributions
When submitting code that was generated or significantly modified by an agent:
Clearly indicate which parts were agent-assisted
Provide information about the agent used
Ensure the code follows Django's coding standards
Be prepared to explain and defend the agent's suggestions
Take responsibility for the quality of the submission
JavaScript: python -m tox -e javascript (runs npm install then npm test from repo root).
Coding Style & Naming Conventions
Python: 4-space indentation, PEP 8, prefer explicit imports; keep lines readable and avoid overlong expressions.
Formatting and import order are enforced by black (check-only) and isort; lint with flake8.
Tests follow test_*.py and Test* naming; co-locate regression tests near the affected module.
Docs use reStructuredText with Sphinx roles; keep :ref: and .. versionadded:: markers consistent.
Testing Guidelines
Use Django’s test runner via ./runtests.py; pass a label to scope by app or test path for faster feedback.
Add regression coverage with minimal fixtures; prefer SimpleTestCase/TestCase over heavier integration when possible.
For optional databases, install matching tests/requirements/*.txt and run with --settings or dedicated tox envs (e.g., -e postgres).
JavaScript changes should be covered in js_tests/ and aligned with related Python behaviors when applicable.
Commit & Pull Request Guidelines
Commits mirror existing history: short past-tense statements with Trac ticket references and a period, e.g., Fixed #12345 -- Clarified middleware docs..
PRs target main and fill .github/pull_request_template.md: include ticket number (or N/A), branch description, AI assistance disclosure, and checklist items.
Link or update the Trac ticket (“Has patch”), include tests/docs updates, and attach light/dark screenshots for UI tweaks.
Keep diffs focused; prefer smaller, reviewable changes and note any follow-ups or compatibility considerations in the PR description.
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Overview
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. This repository contains the Django core codebase, including the ORM, template system, admin interface, and various contrib applications.
Development Commands
Running Tests
# Install dependencies (from repo root)cd tests
python -m pip install -e ..
python -m pip install -r requirements/py3.txt
# Run all tests
./runtests.py
# Run specific test module
./runtests.py <module_name># Example: ./runtests.py generic_relations i18n# Run specific test class
./runtests.py <module_name>.tests.<TestClass># Example: ./runtests.py i18n.tests.TranslationTests# Run specific test method
./runtests.py <module_name>.tests.<TestClass>.<test_method># Example: ./runtests.py i18n.tests.TranslationTests.test_lazy_objects# Run tests with debug SQL logging
./runtests.py <module_name> --debug-sql --verbosity=2
# Run tests in serial (to see full tracebacks)
./runtests.py <module_name> --parallel=1
# Run selenium tests
./runtests.py --selenium=firefox,chrome --headless
# Test bisection (to find interfering tests)
./runtests.py --bisect <failing_test># Test pairing (to find tests with side-effects)
./runtests.py --pair <failing_test>
Code Quality Checks
# Install and run pre-commit hooks
python -m pip install pre-commit
pre-commit install
pre-commit run --all-files
# Run all checks with tox
python -m pip install tox
tox
# Run specific linters
tox -e black # Code formatting
tox -e isort # Import sorting
tox -e flake8 # Linting
tox -e docs # Documentation spelling check# Format code manually
black .
isort django tests scripts
# Run JavaScript tests
tox -e javascript
# or: npm install && npm test
Documentation
cd docs
make html # Build HTML documentation
make spelling # Run spelling checker
Code Architecture
Main Django Package Structure
django/apps/ - Application registry and configuration
Use black for formatting (88 character line length)
Use isort for import sorting
Follow PEP 8 with Django-specific conventions
Use snake_case for variables/functions/methods, InitialCaps for classes
Docstrings follow PEP 257
Max line length: 88 characters for code, 79 for docstrings/comments
Import Order
Future imports
Standard library
Third-party libraries
Django components (absolute imports)
Local Django components (relative imports)
try/except imports
Alphabetize within each group.
String Formatting
Use %-formatting, f-strings, or str.format() for readability. F-strings should only use plain variable/property access. Never use f-strings for translatable strings.
Testing
Use assertRaisesMessage() and assertWarnsMessage() instead of plain assertRaises() and assertWarns()
Use assertIs(…, True/False) for testing boolean values
Test docstrings should state expected behavior without preambles like "Tests that"
Contributing Guidelines
Workflow
Django requires a Trac ticket for non-trivial changes: