flask

bởi microsoft

Các phương pháp hay nhất cho phát triển web Flask bao gồm định tuyến, blueprint và kiểm thử.

npx skills add https://github.com/microsoft/debugpy --skill flask

Skill: Flask

Best practices for Flask web development including routing, blueprints, and testing.

When to Use

Apply this skill when building Flask web applications or APIs — routing, blueprints, extensions, and testing.

Project Structure

  • Use the application factory pattern (create_app()) to avoid global state and enable testing.
  • Organize features into Blueprints; register them in the factory.
  • Keep configuration in a config.py with classes like DevelopmentConfig, ProductionConfig.

Routing and Views

  • Prefer explicit HTTP method decorators (@app.get, @app.post) over generic @app.route with methods=[...].
  • Validate request data early; return 400 errors for malformed input before processing.
  • Use flask.abort() with appropriate HTTP codes rather than returning error responses manually.

Extensions

  • Initialize extensions lazily with ext.init_app(app) inside the factory, not at module level.
  • Common extensions: Flask-SQLAlchemy, Flask-Migrate, Flask-Login, Flask-WTF, Flask-CORS.

Testing

  • Use app.test_client() for HTTP-level tests and app.test_request_context() for unit tests.
  • Use pytest fixtures to create the app and client; scope appropriately (session for the app, function for the client).
  • Set TESTING=True and use a separate test database.

Pitfalls

  • Never use the development server (app.run()) in production — use Gunicorn or uWSGI.
  • Avoid storing mutable state on the app object; use g for request-scoped data.
  • Never hardcode SECRET_KEY — load from environment variables.

Thêm skills từ microsoft

oss-growth
microsoft
Cá tính tăng trưởng OSS
official
winapp-ui-automation
microsoft
Kiểm tra và tương tác với giao diện ứng dụng Windows đang chạy từ dòng lệnh bằng UI Automation (UIA). Sử dụng khi một tác nhân AI hoặc nhà phát triển cần kiểm tra giao diện người dùng...
official
accessibility-aria-expert
microsoft
Phát hiện và sửa các vấn đề về khả năng tiếp cận trong giao diện web React/Fluent UI. Sử dụng khi xem xét mã để đảm bảo tương thích với trình đọc màn hình, sửa nhãn ARIA, đảm bảo…
official
generate-canvas-app
microsoft
[DEPRECATED — sử dụng canvas-app thay thế] Tạo một ứng dụng canvas Power Apps hoàn chỉnh.
official
django
microsoft
Các phương pháp tốt nhất cho phát triển web Django bao gồm models, views, templates và testing.
official
github-issue-creator
microsoft
Chuyển đổi ghi chú thô, nhật ký lỗi, ghi âm giọng nói hoặc ảnh chụp màn hình thành báo cáo vấn đề markdown sắc nét theo phong cách GitHub. Sử dụng khi người dùng dán thông tin lỗi, lỗi…
official
python-package-management
microsoft
Sử dụng uv để quản lý phụ thuộc và poethepoet để tự động hóa tác vụ.
official
runtime-validation
microsoft
Xác thực thời gian chạy cho các ứng dụng đã di chuyển — bao gồm chiến lược kiểm thử (giai đoạn lập kế hoạch) và thực thi kiểm thử (giai đoạn xác thực): xác minh khởi động,…
official