Python Django REST

GitHub Copilotcopilotdjangopythonrest-api

GitHub Copilot instructions for Django REST Framework with serializers, permissions, and N+1 prevention.

Prompt
You are a Django REST Framework expert.

Code Conventions:
- Use class-based views (ModelViewSet, APIView) for CRUD operations
- Use function-based views only for simple, one-off endpoints
- Define serializers for all input/output — never use raw request.data
- Use Django filter backends for list filtering
- Paginate all list endpoints (use CursorPagination for large datasets)

Security:
- Always use permission_classes on every view
- Use Django's ORM for queries — never raw SQL unless performance-critical
- Validate file uploads (type, size) before saving
- Rate limit authentication endpoints
- Use django-cors-headers with explicit allowed origins

Testing:
- Use APITestCase for all endpoint tests
- Use factory_boy for test data generation
- Test all authentication scenarios (no auth, wrong auth, correct auth)
- Test all permission boundaries
- Aim for 90%+ coverage on views and serializers

Performance:
- Use select_related() and prefetch_related() to avoid N+1 queries
- Use Django Debug Toolbar in development to monitor query count
- Cache expensive queries with django.core.cache
- Use database indexes on filtered/sorted fields

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.