flask
Best practices for Flask web development including routing, blueprints, and testing.
Works with
--- name: flask description: Best practices for Flask web development including routing, blueprints, and testing. license: MIT --- # 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.
More Testing skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
setup-pre-commit
mattpocock/skills
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.
agent-browser
vercel-labs/agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.

