drf
Use when building, securing, or fixing REST APIs with Django REST Framework (anything importing rest_framework). Triggers on: "DRF", "serializer", "ViewSet", "APIView", "router", "permission classes", "throttling", "pagination". Not for pure Django ORM/template/form/admin work — use django for those.
- License 许可
- Unlicense
- 最近更新
- 2026-10-28
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- drf
- description
- Use when building, securing, or fixing REST APIs with Django REST Framework (anything importing rest_framework). Triggers on: "DRF", "serializer", "ViewSet", "APIView", "router", "permission classes", "throttling", "pagination". Not for pure Django ORM/template/form/admin work — use django for those.
02 资源文件 11
- 参考文档evals/evals.json7.9 KB
- 参考文档evals/trigger-evals.json3.2 KB
- 参考文档references/auth-permissions.md11.0 KB
- 参考文档references/filtering-pagination.md10.8 KB
- 参考文档references/internals.md14.7 KB
- 参考文档references/parsers-renderers.md8.0 KB
- 参考文档references/REFERENCE.md2.4 KB
- 参考文档references/requests-responses.md8.5 KB
- 参考文档references/serializers-fields.md18.1 KB
- 参考文档references/testing-settings.md10.5 KB
- 参考文档references/views-viewsets.md13.0 KB
03 SKILL.md 正文
Django REST Framework Reference
Use this skill for DRF API implementation: serializers, views, viewsets, routers, authentication, permissions, throttling, filtering, pagination, testing, and configuration. Apply the critical rules below, then route to the reference files the task needs.
Critical Rules
fieldsorexcludeis mandatory — Since v3.3.0,ModelSerializer.MetaMUST declarefieldsorexclude. Omitting both raisesImproperlyConfigured.- Writable nested representations require explicit code —
ModelSerializer.create()and.update()do NOT support writable nested serializers by default. You must override these methods. - Reverse relations are NOT auto-included —
ModelSerializerandHyperlinkedModelSerializerdo not include reverse FK/M2M fields. Add them explicitly tofields. - M2M with
throughmodel defaults to read-only — Relational fields targetingManyToManyFieldwith athroughmodel are automaticallyread_only=True. - Object-level permissions skip creation —
has_object_permission()is NOT called during object creation (POST). Restrict creation inperform_create()or the serializer. - Permission composition precedence —
~highest, then&, then|. Use parentheses to be explicit. HiddenFielddisappears in partial updates —HiddenField()does not appear inpartial=Trueserializers (PATCH requests).UniqueTogetherValidatortreats fields as required — All fields in aUniqueTogetherValidatorare implicitlyrequired=True, except those withdefaultvalues.- ViewSet
actionunavailable in early methods —self.actionis NOT set whenget_parsers,get_authenticators, orget_content_negotiatorare called. - No trailing slash in router
register()prefix — Routers append slashes automatically.router.register(r'users', ...)notr'users/'. - Throttling uses non-atomic cache operations — Race conditions possible under high concurrency. Not a security measure against brute force.
CursorPaginationdefaults to-createdordering — Models MUST have acreatedfield, or override theorderingattribute.Requestuses composition, not inheritance — DRFRequestwraps DjangoHttpRequestvia composition. Access standard attributes viarequest.META,request.sessionetc.extra_kwargssilently ignored for explicit fields — If you declare a field on the serializer class AND haveextra_kwargsfor it, theextra_kwargsdo nothing.- Serializer relations cause N+1 queries — Nested and related serializer fields fire one query per object during list serialization. Pair every list-returning view with
select_related/prefetch_relatedon its queryset (django-discipline's ORM rule applies to DRF views too).
When Not To Use This Skill
- Pure Django ORM/views/templates — Load
djangofor models, querysets, template rendering, forms, admin, or middleware outsiderest_framework. - FastAPI / Django Ninja APIs — This skill is
rest_framework-only; do not apply DRF patterns to other API frameworks. - HTMX interaction flows — For partial rendering, swaps, triggers, load
htmx. - Tabler UI work — For Tabler components and CSS patterns, load
tabler. - HTTP status code deep semantics — For 400 vs 422, 401 vs 403, redirect codes, load
http-status-codes. - Project-specific business rules — Load the project's custom skill.
Routing
Choose the primary reference; add one secondary reference only when the task clearly crosses domains. Keep the answer grounded in the reference files actually used.
Single-domain (one file):
| Use for | File |
|---|---|
| Serializer hierarchy, field types, relations, validators, nested writes | references/serializers-fields.md |
APIView, generics, mixins, viewsets, @action, routers |
references/views-viewsets.md |
| Authentication, permissions, throttling | references/auth-permissions.md |
| Filter backends, search, ordering, pagination | references/filtering-pagination.md |
| Request, Response, exceptions, status codes | references/requests-responses.md |
| Parsers, renderers, negotiation, metadata | references/parsers-renderers.md |
| Test utilities, complete settings reference | references/testing-settings.md |
| Dispatch flow, parsing pipeline, versioning, schemas | references/internals.md |
Cross-domain (two files):
- Full CRUD API →
views-viewsets.md+serializers-fields.md - Secured API →
auth-permissions.md+views-viewsets.md - Filtered/paginated lists →
filtering-pagination.md+views-viewsets.md - Custom content handling →
parsers-renderers.md+requests-responses.md - Serializer with permissions →
serializers-fields.md+auth-permissions.md
Output Expectations
- Name the reference files used.
- State the minimum tests or verification steps.
- Call out the critical DRF rules applied.
04 同仓库更多 Skills
wizard
Generate an interactive bash wizard that walks a human through a manual procedure — third-party setup, credential provisioning, a one-off migration — opening URLs, capturing values, confirming each step, and writing .env files and CI secrets (GitHub and Gitea/Forgejo Actions).
restore-test-pyramid
Analyze the project's E2E suite and push every assertion that doesn't need a real browser down to a faster integration or unit test, proving each migration honest before thinning E2E.
ponytail-debt
Harvest SHORTCUT markers from the codebase and report them grouped by file, flagging any missing upgrade paths.
humanify
Repair an inherited or human-blocked ticket for agent implementation, or finish its explicit human-only outcome.
fix-pr
Repair an existing pull request's review findings and target-branch conflicts, verify the result, and update the same open PR.
feature-milestones
Reconstruct a fragmented backlog as finishable feature milestones with explicit delivery boundaries and an approval-gated tracker update.