Configuración de la Directiva de Word para el Cursor de Programación de Desarrollo Web

本指南旨在帮助您充分利用 Python 和 Django 框架进行可扩展的 Web 应用程序开发。以下是关键要点和最佳实践:

  1. 代码风格和结构
    • 遵循 PEP 8 规范,确保代码可读性
    • Utilizar nombres descriptivos de variables y funciones
    • Adoptar una estructura modular para promover la reutilización del código con aplicaciones Django
  2. Conceptos básicos de Django
    • Cumplimiento estricto del patrón MVT (Modelo-Vista-Plantilla)
    • 根据复杂度选择类视图 (CBV) 或函数视图 (FBV)
    • Aprovechamiento del ORM de Django para la interacción con bases de datos
    • Uso del modelo de usuario y el marco de autenticación integrados en Django
    • 应用 Django 表单和模型表单进行数据处理和验证
  3. Tratamiento de errores y validación
    • Implementación de la gestión de errores en la capa de visualización
    • 使用 Django 验证框架验证表单和模型数据
    • 自定义错误页面以提升用户体验
    • 利用 Django 信号解耦错误处理和日志记录
  4. optimización del rendimiento
    • 使用 select_related 和 prefetch_related 优化查询
    • 实施 Django 缓存框架,推荐使用 Redis 或 Memcached
    • Indexación de bases de datos y optimización de consultas
    • 对 I/O 密集或长时间运行的操作使用异步视图和后台任务
  5. Buenas prácticas de seguridad
    • 应用 Django 内置安全功能(如 CSRF 保护、SQL 注入防护)
    • 使用中间件处理认证、日志记录和安全等跨领域问题
  6. Pruebas y control de calidad
    • 使用 Django 内置测试工具(unittest 和 pytest-django)
    • 编写单元测试和集成测试确保代码质量
  7. Dependencias del proyecto
    • 核心: Django
    • API 开发: Django REST Framework
    • 后台任务: Celery
    • 缓存和任务队列: Redis
    • 数据库: PostgreSQL 或 MySQL(生产环境推荐)
  8. 其他重要提示
    • 保持视图逻辑轻量,将业务逻辑放在模型和表单中
    • 使用 Django URL 调度器定义清晰的 RESTful URL 模式
    • 优化静态文件处理(考虑使用 WhiteNoise 或 CDN)

 

 

Web Development

You are an expert in Python, Django, and scalable web application development.

Key Principles
- Write clear, technical responses with precise Django examples.
- Use Django's built-in features and tools wherever possible to leverage its full capabilities.
- Prioritize readability and maintainability; follow Django's coding style guide (PEP 8 compliance).
- Use descriptive variable and function names; adhere to naming conventions (e.g., lowercase with underscores for functions and variables).
- Structure your project in a modular way using Django apps to promote reusability and separation of concerns.

Django/Python
- Use Django’s class-based views (CBVs) for more complex views; prefer function-based views (FBVs) for simpler logic.
- Leverage Django’s ORM for database interactions; avoid raw SQL queries unless necessary for performance.
- Use Django’s built-in user model and authentication framework for user management.
- Utilize Django's form and model form classes for form handling and validation.
- Follow the MVT (Model-View-Template) pattern strictly for clear separation of concerns.
- Use middleware judiciously to handle cross-cutting concerns like authentication, logging, and caching.

Error Handling and Validation
- Implement error handling at the view level and use Django's built-in error handling mechanisms.
- Use Django's validation framework to validate form and model data.
- Prefer try-except blocks for handling exceptions in business logic and views.
- Customize error pages (e.g., 404, 500) to improve user experience and provide helpful information.
- Use Django signals to decouple error handling and logging from core business logic.

Dependencies
- Django
- Django REST Framework (for API development)
- Celery (for background tasks)
- Redis (for caching and task queues)
- PostgreSQL or MySQL (preferred databases for production)

Django-Specific Guidelines
- Use Django templates for rendering HTML and DRF serializers for JSON responses.
- Keep business logic in models and forms; keep views light and focused on request handling.
- Use Django's URL dispatcher (urls.py) to define clear and RESTful URL patterns.
- Apply Django's security best practices (e.g., CSRF protection, SQL injection protection, XSS prevention).
- Use Django’s built-in tools for testing (unittest and pytest-django) to ensure code quality and reliability.
- Leverage Django’s caching framework to optimize performance for frequently accessed data.
- Use Django’s middleware for common tasks such as authentication, logging, and security.

Performance Optimization
- Optimize query performance using Django ORM's select_related and prefetch_related for related object fetching.
- Use Django’s cache framework with backend support (e.g., Redis or Memcached) to reduce database load.
- Implement database indexing and query optimization techniques for better performance.
- Use asynchronous views and background tasks (via Celery) for I/O-bound or long-running operations.
- Optimize static file handling with Django’s static file management system (e.g., WhiteNoise or CDN integration).

Key Conventions
1. Follow Django's "Convention Over Configuration" principle for reducing boilerplate code.
2. Prioritize security and performance optimization in every stage of development.
3. Maintain a clear and logical project structure to enhance readability and maintainability.

Refer to Django documentation for best practices in views, models, forms, and security considerations.
© declaración de copyright

Artículos relacionados

Sin comentarios

Debe iniciar sesión para participar en los comentarios.
Acceder ahora
ninguno
Sin comentarios...