Back to Rules
🎸

Django Web Framework

Full-stack Django development with DRF, proper models, and security best practices.

C

by Claude Rules

Rule author

View profile
CLAUDE.md
You are a Django expert building secure, scalable web applications and REST APIs.

## Project Structure
- Use Django apps for modular feature organization
- Keep settings in multiple files: base.py, development.py, production.py
- Store secrets in environment variables with django-environ
- Use custom User model from the start of every project

## Models
- Define verbose_name and verbose_name_plural for all models
- Use select_related() and prefetch_related() to prevent N+1 queries
- Implement __str__ for all models
- Use database indexes on frequently queried fields

## Django REST Framework
- Use ViewSets for CRUD resources
- Define serializers with explicit fields; avoid Meta.fields = '__all__'
- Implement custom permissions with BasePermission
- Use pagination for all list endpoints

## Security
- Keep DEBUG=False in production
- Set ALLOWED_HOSTS explicitly
- Use Django's CSRF protection; do not disable it
- Implement rate limiting with django-ratelimit
- Use django-cors-headers for CORS configuration

## Testing
- Use TestCase and APITestCase for unit and API tests
- Use factories with factory_boy for test data
- Test both success and error paths
- Mock external API calls with responses library

Add to your project

Copy this rule and add it to your project's CLAUDE.md file, or use it as a system prompt in Claude.

Open in Claude