Files
cps-develop-docs/.github/instructions/django-drf.instructions.md

15 lines
804 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
applyTo: "**/*.py"
description: "用于 Django/DRF 实现关键词Thin View Fat Service、ModelViewSet、Serializer、权限隔离"
---
# Django/DRF 约束
- 严格执行 Thin View, Fat Service复杂业务逻辑进入 Service 层。
- Model 定义显式字段与约束Serializer 禁止 `fields = '__all__'`
- 列表查询必须考虑 `select_related` / `prefetch_related` 防 N+1。
- 视图层通过 `get_queryset``get_permissions``get_serializer_class` 管理数据范围与权限。
- 禁止在 View 中手工拼装错误响应,统一交由异常处理与全局响应包装。
- URL 命名与版本化保持一致,非标准接口补充 `@extend_schema`
- 参考规范:`03 - Coding & Frameworks/02 - Framework Development Specification/Django_DRF开发规范.md`