Django REST Framework Patterns
This skill provides reference patterns for building APIs with Django REST Framework (DRF).
It covers serializer design, viewset architecture, routing, filtering, pagination,
authentication, and permissions.
When to Use
- Project has
djangorestframework in its dependencies
- Building or modifying REST API endpoints
- Designing serializer validation or nested write logic
- Configuring authentication, permissions, or throttling
- Reviewing DRF code for performance or correctness issues
Style Conventions
- Use
| None instead of Optional for type hints
- Maximum line length: 100 characters
- Prefer
select_related / prefetch_related in viewset get_queryset(), not in serializers
- Keep serializers thin -- move complex logic to model methods or services
Reference Files
- serializers.md - Serializer patterns: ModelSerializer vs
Serializer, nested writes, validation, field customization, performance
- viewsets.md - ViewSet patterns: ModelViewSet vs GenericViewSet,
routers, custom actions, filtering, pagination, throttling
- permissions-auth.md - Authentication and permissions:
token/JWT/session auth, permission classes, object-level permissions, rate limiting
Quick Reference
Common Settings
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework_simplejwt.authentication.JWTAuthentication",
"rest_framework.authentication.SessionAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 20,
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.SearchFilter",
"rest_framework.filters.OrderingFilter",
],
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.AnonRateThrottle",
"rest_framework.throttling.UserRateThrottle",
],
"DEFAULT_THROTTLE_RATES": {
"anon": "100/hour",
"user": "1000/hour",
},
}
Typical File Layout
app/
serializers.py # All serializers for this app
views.py # ViewSets and API views
urls.py # Router registration
permissions.py # Custom permission classes
filters.py # Custom filter classes
pagination.py # Custom pagination classes
throttling.py # Custom throttle classes
tests/
test_api.py # API endpoint tests
Source: weorbitant/compound-engineering-feat-python-plugin — distributed by TomeVault.
1---2name: django-drf3description: Django REST Framework patterns for serializers, viewsets, routers, permissions, and authentication. Use when building or reviewing projects with djangorestframework in dependencies. Use when this capability is needed.4---56# Django REST Framework Patterns78This skill provides reference patterns for building APIs with Django REST Framework (DRF).9It covers serializer design, viewset architecture, routing, filtering, pagination,10authentication, and permissions.1112## When to Use1314- Project has `djangorestframework` in its dependencies15- Building or modifying REST API endpoints16- Designing serializer validation or nested write logic17- Configuring authentication, permissions, or throttling18- Reviewing DRF code for performance or correctness issues1920## Style Conventions2122- Use `| None` instead of `Optional` for type hints23- Maximum line length: 100 characters24- Prefer `select_related` / `prefetch_related` in viewset `get_queryset()`, not in serializers25- Keep serializers thin -- move complex logic to model methods or services2627## Reference Files2829- [serializers.md](./references/serializers.md) - Serializer patterns: ModelSerializer vs30 Serializer, nested writes, validation, field customization, performance31- [viewsets.md](./references/viewsets.md) - ViewSet patterns: ModelViewSet vs GenericViewSet,32 routers, custom actions, filtering, pagination, throttling33- [permissions-auth.md](./references/permissions-auth.md) - Authentication and permissions:34 token/JWT/session auth, permission classes, object-level permissions, rate limiting3536## Quick Reference3738### Common Settings3940```python41REST_FRAMEWORK = {42 "DEFAULT_AUTHENTICATION_CLASSES": [43 "rest_framework_simplejwt.authentication.JWTAuthentication",44 "rest_framework.authentication.SessionAuthentication",45 ],46 "DEFAULT_PERMISSION_CLASSES": [47 "rest_framework.permissions.IsAuthenticated",48 ],49 "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",50 "PAGE_SIZE": 20,51 "DEFAULT_FILTER_BACKENDS": [52 "django_filters.rest_framework.DjangoFilterBackend",53 "rest_framework.filters.SearchFilter",54 "rest_framework.filters.OrderingFilter",55 ],56 "DEFAULT_THROTTLE_CLASSES": [57 "rest_framework.throttling.AnonRateThrottle",58 "rest_framework.throttling.UserRateThrottle",59 ],60 "DEFAULT_THROTTLE_RATES": {61 "anon": "100/hour",62 "user": "1000/hour",63 },64}65```6667### Typical File Layout6869```70app/71 serializers.py # All serializers for this app72 views.py # ViewSets and API views73 urls.py # Router registration74 permissions.py # Custom permission classes75 filters.py # Custom filter classes76 pagination.py # Custom pagination classes77 throttling.py # Custom throttle classes78 tests/79 test_api.py # API endpoint tests80```8182---83> Source: [weorbitant/compound-engineering-feat-python-plugin](https://github.com/weorbitant/compound-engineering-feat-python-plugin) — distributed by [TomeVault](https://tomevault.io).84<!-- tomevault:4.0:skill_md:2026-05-22 -->