后端迁移
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- 运维部署
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- Docker
- 底层运行要求
- Python · Docker
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- 读取环境变量
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: django
description: Django + FastAPI development. Project structure, DRF serializers/viewsets, Pydantic, async Djang…
category: 运维部署
runtime: Python / Docker
---
# django 输出预览
## PART A: 任务判断
- 适用问题:部署、CI、环境检查、发布或运维排障。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Activate When / Workflow / Step 1: Project Assessment”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于部署、CI、环境检查、发布或运维排障,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Activate When / Workflow / Step 1: Project Assessment”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、读取环境变量、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、读取环境变量;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/godmode` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、读取环境变量。
先用一个小任务确认它会围绕“Activate When / Workflow / Step 1: Project Assessment”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: django
description: Django + FastAPI development. Project structure, DRF serializers/viewsets, Pydantic, async Djang…
category: 运维部署
source: tomevault-io/skills-registry
---
# django
## 什么时候使用
- 把部署运维方向的常用动作沉淀成 Agent 可调用的技能 适合处理部署、CI、发布、回滚、环境检查和运维排障,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤…
- 面向部署、CI、环境检查、发布或运维排障,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Activate When / Workflow / Step 1: Project Assessment」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、读取环境变量;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "django" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Activate When / Workflow / Step 1: Project Assessment
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Python / Docker | 读取文件、写入/修改文件、读取环境变量 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Django — Django & FastAPI Development
Activate When
- User invokes
/godmode:django - User says "Django", "Django project", "Django app"
- User mentions "FastAPI", "Pydantic", "dependency injection"
- User asks about "DRF", "Django REST Framework", "serializers", "viewsets"
- User mentions "Django admin", "admin customization"
- User asks about "ASGI", "async Django", "Uvicorn", "Daphne"
- User says "django view", "views.py", "Django view for"
- When
/godmode:planidentifies a Python web project - When
/godmode:reviewflags Django or FastAPI architecture issues
Workflow
Step 1: Project Assessment
Understand the Python web application context:
PYTHON WEB PROJECT ASSESSMENT:
Project: <name and purpose>
Framework: <Django | FastAPI | both (Django + FastAPI hybrid)>
Type: <monolith | microservice | API-only | full-stack with templates>
Scale: <expected RPS, team size, data volume>
Database: <PostgreSQL, MySQL, SQLite, MongoDB>
Auth: <Django auth, OAuth2, JWT, API keys>
Async needs: <WebSocket, background tasks, streaming, long-polling>
Deployment: <Gunicorn+Nginx, Docker, serverless, PaaS>
Existing code: <greenfield | existing Django project | migration>
If the user hasn't specified, ask: "Are you building with Django, FastAPI, or both? Is this an API-only service or full-stack with templates?"
Step 2: Django Project Structure
Design the Django project layout following best practices:
DJANGO PROJECT STRUCTURE:
project/
├── manage.py
├── pyproject.toml # Dependencies, tools config (ruff, mypy)
├── config/ # Project-level configuration
│ ├── __init__.py
│ ├── settings/
│ │ ├── __init__.py
│ │ ├── base.py # Shared settings
│ │ ├── development.py # Dev overrides (DEBUG=True, etc.)
│ │ ├── production.py # Production settings (security, caching)
│ │ └── test.py # Test settings (fast password hasher, in-memory)
│ ├── urls.py # Root URL configuration
│ ├── wsgi.py # WSGI entry point
Step 3: Django REST Framework Patterns
Design the API layer with DRF:
DRF ARCHITECTURE PATTERNS:
1. Serializers — Data validation and transformation:
# Base serializer pattern
class UserSerializer(serializers.ModelSerializer):
full_name = serializers.SerializerMethodField()
class Meta:
model = User
fields = ['id', 'email', 'full_name', 'created_at']
read_only_fields = ['id', 'created_at']
def get_full_name(self, obj):
return f"{obj.first_name} {obj.last_name}"
Step 4: FastAPI Architecture
Design FastAPI applications with dependency injection:
FASTAPI APPLICATION ARCHITECTURE:
app/
├── main.py # FastAPI app instance, lifespan events
├── config.py # Pydantic Settings for configuration
├── dependencies.py # Shared dependencies (get_db, get_current_user)
├── database.py # SQLAlchemy/databases async engine setup
│
├── users/
│ ├── __init__.py
│ ├── router.py # APIRouter with endpoints
│ ├── schemas.py # Pydantic models (request/response)
│ ├── models.py # SQLAlchemy/SQLModel ORM models
│ ├── service.py # Business logic
│ ├── repository.py # Database queries
Step 5: Async Django & ASGI
ASGI setup: config/asgi.py with get_asgi_application().
For WebSockets: channels ProtocolTypeRouter + AuthMiddlewareStack.
Use httpx.AsyncClient (not requests) in async views.
Step 6: Django Admin
Admin patterns: @admin.register(Model) + ModelAdmin.
Required: list_display, list_filter, search_fields, list_select_related.
Optional: list_editable, inlines, actions, readonly_fields.
Step 7: Database Optimization
Optimize Django ORM queries:
DJANGO ORM OPTIMIZATION:
1. N+1 query prevention:
# BAD: N+1 queries (1 query for orders + N queries for customers)
orders = Order.objects.all()
for order in orders:
print(order.customer.name) # Each access triggers a query!
# GOOD: select_related for ForeignKey/OneToOne (SQL JOIN)
orders = Order.objects.select_related('customer').all()
# GOOD: prefetch_related for ManyToMany/reverse FK (separate query)
orders = Order.objects.prefetch_related('items', 'items__product').all()
# GOOD: Prefetch with custom queryset
Step 8: Validation
Validate the Python web project:
PYTHON WEB PROJECT AUDIT:
| Check | Status |
|--|--|
| Business logic in services (not views) | PASS | FAIL |
| Serializers validate all input | PASS | FAIL |
| No N+1 queries (select/prefetch_related) | PASS | FAIL |
| Database indexes on filtered/ordered fields | PASS | FAIL |
| Custom user model (AbstractUser) | PASS | FAIL |
| Settings split by environment | PASS | FAIL |
| Secrets from environment variables | PASS | FAIL |
| Admin performance (list_select_related) | PASS | FAIL |
| Pagination on all list endpoints | PASS | FAIL |
| Authentication and permissions configured | PASS | FAIL |
| Tests use factories (Factory Boy) | PASS | FAIL |
Step 9: Deliverables
Generate the project artifacts:
PYTHON WEB PROJECT COMPLETE:
Artifacts:
- Framework: <Django | FastAPI | hybrid>
- Apps/modules: <N> apps, <M> models
- API: <DRF ViewSets | FastAPI routers> with <N> endpoints
- Admin: <N> ModelAdmin configs customized
- Database: <PostgreSQL> with <N> indexes, optimized queries
- Async: <ASGI configured | WSGI only>
- Audit: <PASS | NEEDS REVISION>
Next steps:
-> /godmode:api — Document the API with OpenAPI spec
-> /godmode:test — Write model, view, and integration tests
-> /godmode:deploy — Deploy with Gunicorn+Nginx or Docker
-> /godmode:migrate — Handle database schema migrations
Commit: "django: <project> — <framework>, <N> apps, <M> endpoints, <admin/async config>"
# Django development and testing
python manage.py check --deploy
pytest --tb=short
python manage.py migrate --check
Key Behaviors
Never ask to continue. Loop autonomously until done.
# Django diagnostics
python manage.py check --deploy
python manage.py test --parallel --verbosity=2
python manage.py makemigrations --check --dry-run
python manage.py showmigrations | grep '\[ \]'
IF query count per list view > 5: add select_related/prefetch_related. WHEN test coverage < 80%: add tests before shipping. IF response time P95 > 200ms: profile with django-debug-toolbar.
- Services own business logic. Views dispatch, serializers validate, services contain logic.
- Fat models, thin views — but not too fat. Cross-model rules belong in services.
- DRF serializers are contracts. Never
fields = '__all__'. Separate create vs read serializers. - Eliminate N+1 queries. select_related for FK, prefetch_related for M2M. Use django-debug-toolbar.
- FastAPI dependencies compose. Auth, pagination, DB sessions as composable deps.
- Pydantic is source of truth. Validation, serialization, documentation in one place.
- Admin is a power tool. Customize list_display, search, filters. Admin N+1 is the top perf issue.
Flags & Options
| Flag | Description |
|---|---|
| (none) | Full Django/FastAPI workflow |
--audit |
Audit existing Django or FastAPI project |
--django |
Django-specific guidance only |
HARD RULES
- NEVER put business logic in views or serializers — business rules belong in service functions
- NEVER use
fields = '__all__'in DRF serializers — explicitly list every field to prevent data leakage - NEVER use the default User model — always create a custom user model with AbstractUser at project start
- NEVER use synchronous HTTP calls (requests) in async views — use httpx.AsyncClient instead
- NEVER skip database indexes on fields used in filter(), order_by(), or WHERE clauses
- ELIMINATE ALL N+1 queries with select_related (ForeignKey) and prefetch_related (ManyToMany)
- ALL admin ModelAdmin classes MUST use list_select_related to prevent N+1 in the admin interface
- ALL API list endpoints MUST have pagination configured — unbounded queries are not acceptable
Auto-Detection
1. Scan for manage.py, settings.py → Django; main.py with FastAPI → FastAPI; both → hybrid
2. Check REST_FRAMEWORK config, AUTH_USER_MODEL, DATABASES engine
3. Scan for services.py/selectors.py (layering), factories.py (testing), Celery (tasks)
4. Maturity: scaffold | structured | optimized | production-ready
Output Format
End every Django skill invocation with this summary block:
DJANGO RESULT:
Action: <scaffold | model | view | serializer | service | optimize | test | audit | upgrade>
Files created/modified: <N>
Models created/modified: <N>
Views created/modified: <N>
Migrations created: <N>
Tests passing: <yes | no | skipped>
Build status: <passing | failing | not-checked>
Issues fixed: <N>
Notes: <one-line summary>
TSV Logging
Log every invocation to .godmode/ as TSV. Create on first run.
timestamp project action files_count models_count views_count migrations_count tests_status notes
Success Criteria
python manage.py check --deploypasses with 0 critical warningspython manage.py testpasses; coverage >= 80%- No business logic in views/serializers — services only
- No
fields = '__all__'— explicit field lists - All querysets use select_related/prefetch_related; list views <= 5 queries, detail <= 3
- Filterable/sortable fields have DB indexes
- Custom user model (not default auth.User)
- Migrations consistent (
makemigrations --check)
Error Recovery
| Failure | Action |
|---|---|
| manage.py check fails | Fix CRITICAL first (middleware, ALLOWED_HOSTS) |
| Tests fail | Check test DB permissions, fixtures |
| Migration conflict | makemigrations --merge |
| N+1 detected | Add select_related/prefetch_related |
Keep/Discard Discipline
KEEP if: tests pass AND quality improved AND no regressions
DISCARD if: tests fail OR performance regressed. Revert before proceeding.
Stop Conditions
STOP when: all tasks validated OR max iterations reached.
Guard: python manage.py test && python manage.py check --deploy.
On failure: git reset --hard HEAD~1.
Source: arbazkhan971/godmode — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核