Agentic-skills django-development-best-practices
Comprehensive Django development framework with prioritized rules across models, views, templates, security, and performance. Use when building Django applications, writing models, creating views, implementing authentication, or optimizing Django projects.
install
source · Clone the upstream repo
git clone https://github.com/GNSubrahmanyam/agentic-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/GNSubrahmanyam/agentic-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/django" ~/.claude/skills/gnsubrahmanyam-agentic-skills-django-development-best-practices && rm -rf "$T"
manifest:
skills/django/SKILL.mdsource content
Django Development Best Practices
Comprehensive performance and development optimization guide for Django applications, containing 60+ rules across 9 categories, prioritized by impact to guide automated development and code generation.
When to Apply
Reference these guidelines when:
- Building new Django applications or features
- Writing models, views, templates, or forms
- Implementing authentication and security
- Optimizing database queries and performance
- Setting up testing and deployment
- Reviewing Django code for best practices
- Customizing admin interfaces and URL configurations
- Implementing caching strategies and middleware
- Working with static files and media uploads
- Understanding Django signals and advanced patterns
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Security & Authentication | CRITICAL | |
| 2 | Database & Models | CRITICAL | |
| 3 | Views & URLs | HIGH | |
| 4 | Forms | HIGH | |
| 5 | Templates | MEDIUM-HIGH | |
| 6 | Authentication & Authorization | MEDIUM-HIGH | |
| 7 | APIs | MEDIUM-HIGH | |
| 8 | URLs & Admin | MEDIUM-HIGH | / |
| 9 | Email & Tasks | MEDIUM-HIGH | / |
| 10 | Testing | MEDIUM-HIGH | |
| 11 | Performance & Caching | MEDIUM | / |
| 12 | Deployment | MEDIUM | |
| 13 | Advanced Patterns | LOW | |
Quick Reference
1. Security & Authentication (CRITICAL)
: Always enable CSRF protection for formssecurity-csrf-protection
: Use parameterized queries and ORM methodssecurity-sql-injection
: Escape user input in templatessecurity-xss-prevention
: Force HTTPS in productionsecurity-https-only
: Use Django's password hashingsecurity-password-hashing
: Secure session configurationsecurity-session-security
: Secure data signing for integrity and tamper preventionsigning-cryptography
2. Database & Models (CRITICAL)
: Never modify migrations manuallydb-migration-safety
: Add indexes for frequently queried fieldsdb-indexes-strategy
: Use on_delete appropriatelydb-foreign-key-protection
: Use select_related and prefetch_relateddb-n-plus-one-queries
: Use model and database constraintsdb-constraints-validation
: Wrap related operations in transactionsdb-transaction-management
3. Views & URLs (HIGH)
: Choose appropriate view typeviews-function-vs-class
: Handle HTTP methods correctlyviews-http-methods
: Implement proper error responsesviews-error-handling
: Use Django's pagination for large datasetsviews-pagination
: Implement appropriate caching layersviews-caching-strategy
: Use proper serialization for APIsviews-api-serialization
: Proper exception handling and error viewsexceptions-error-handling
: Handling HttpRequest and HttpResponse objectshttp-request-response
4. Forms (HIGH)
: Prefer ModelForm for model-backed formsforms-modelform-usage
: Implement custom validation methodsforms-validation-logic
: Always clean and validate form dataforms-security-cleaning
: Provide clear error messages to usersforms-error-display
: Handle file uploads securelyforms-file-handling
: Use formsets for multiple related formsforms-formsets-usage
: Built-in and custom validators for data validationvalidators
5. Templates (MEDIUM-HIGH)
: Use template inheritance for DRY templatestemplates-inheritance-pattern
: Keep templates simple, logic in viewstemplates-context-data
: Use safe filters carefullytemplates-filters-security
: Manage static files properlytemplates-static-files
: Implement i18n supporttemplates-internationalization
: Minimize template rendering overheadtemplates-performance
6. Authentication & Authorization (MEDIUM-HIGH)
: Implement secure user authenticationauth-user-management
: Use Django's permission systemauth-permissions-groups
: Extend user model when neededauth-custom-user-model
: Secure session handlingauth-session-security
: Password management best practicesauth-password-security
: Third-party authentication integrationauth-social-auth
7. URLs & Admin (MEDIUM-HIGH)
: Organize URL patterns effectivelyurls-configuration-patterns
: Use reverse() for URL generationurls-reverse-urls
: Implement URL namespaces and app namesurls-namespaces
: Customize Django admin interfaceadmin-customization
: Add custom admin actions and filtersadmin-actions-filters
: Secure admin interface accessadmin-security
6. Testing (MEDIUM-HIGH)
: Write appropriate test typestesting-unit-vs-integration
: Use fixtures for test datatesting-fixtures-usage
: Mock external dependenciestesting-mocking-strategy
: Maintain high test coveragetesting-coverage-goals
: Use Django's TestCase subclassestesting-django-testcase
: Use factories for complex test datatesting-factory-pattern
7. Performance (MEDIUM)
: Optimize database queriesperf-query-optimization
: Implement multiple caching layersperf-caching-strategy
: Optimize static file servingperf-static-file-optimization
: Use appropriate database indexesperf-database-indexing
: Order middleware efficientlyperf-middleware-optimization
: Use async views where appropriateperf-async-support
: Asynchronous operations and background tasksasync-views-tasks
: File uploads and storage managementfiles-media-handling
8. Deployment (MEDIUM)
: Separate development and productiondeploy-environment-separation
: Securely manage secrets and keysdeploy-secret-management
: Configure static file servingdeploy-static-files-serving
: Optimize database settingsdeploy-database-configuration
: Implement logging and monitoringdeploy-monitoring-setup
: Implement data backup proceduresdeploy-backup-strategy
: Django settings configuration and environment variablessettings-management
9. Advanced Patterns (LOW)
: Use signals appropriatelyadvanced-signals-usage
: Implement custom middlewareadvanced-middleware-custom
: Create custom model managersadvanced-model-managers
: Extend generic views properlyadvanced-generic-views
: Customize admin interfaceadvanced-admin-customization
: Implement advanced i18n featuresadvanced-internationalization
: Middleware concepts and custom middleware creationmiddleware-basics
: Encoding and text processing for international appsunicode-text-handling
How to Use
Read individual rule files for detailed explanations and code examples:
rules/security-csrf-protection.md rules/db-migration-safety.md rules/views-function-vs-class.md rules/auth-user-management.md rules/admin-customization.md rules/caching-strategy.md
Each rule file contains:
- Impact level and category
- Problem description
- Solution with code examples
- Common mistakes to avoid
- When to apply the rule
Reference Documentation
Detailed guides for complex topics:
references/workflows.md # Development workflow patterns references/middleware-signals.md # Middleware and signals implementation references/deployment-static.md # Static files, media, and deployment
Full Compiled Document
For the complete Django best practices guide with all rules expanded:
AGENTS.md