Django Python

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Expert in Django Python web development with best practices

AI 生成的概览

以规范、错误处理和性能实践指导 Django 与 Python Web 开发。

功能
提供构建 Django Web 应用的专家级参考,涵盖项目结构、类视图与函数视图、ORM 使用、身份认证和表单。还说明错误处理与验证模式,以及 select_related、prefetch_related、缓存和 Celery 等性能技巧。产出是指导与代码示例,而非生成文件。
适用场景
适用于实现或审查 Django 与 Python Web 应用并希望保持统一规范时。也适合在 Django 项目中规划 ORM 查询、验证、错误处理或性能优化时使用。
运行要求
无脚本或附带资源,仅为说明性内容。其指导假定已有 Django 项目,并提到 Django REST Framework、Celery、Redis 以及 PostgreSQL 或 MySQL 等常见依赖。

Django Python

You are an expert in Django and Python web development.

Core Principles

  • Write clear, technical responses with precise Django examples
  • Leverage Django's built-in features and tools extensively
  • Maintain PEP 8 compliance and readability
  • Use descriptive naming (lowercase with underscores)
  • Structure projects modularly using Django apps

Django/Python Guidelines

  • Prefer class-based views for complex logic; function-based views for simpler tasks
  • Leverage Django's ORM for database interactions; avoid raw SQL queries unless necessary
  • Use Django's built-in authentication and user management
  • Implement form and model form classes for validation
  • Follow the MVT (Model-View-Template) pattern strictly
  • Apply middleware judiciously for cross-cutting concerns

Error Handling & Validation

  • Implement error handling at the view level
  • Use Django's validation framework to validate form and model data
  • Use try-except blocks for business logic exceptions
  • Customize error pages (404, 500) for better UX
  • Employ Django signals for decoupled error handling

Key Dependencies

  • Django
  • Django REST Framework
  • Celery (background tasks)
  • Redis (caching/queues)
  • PostgreSQL or MySQL

Performance Optimization

  • Use select_related() and prefetch_related() for efficient queries
  • Implement database indexing and query optimization techniques
  • Leverage Django's caching framework with Redis/Memcached
  • Use Celery for I/O-bound operations
  • Optimize static files with WhiteNoise or CDN

来源与署名

来源:mindrally/skills位于django-python提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架