Flask Cursor Rules Template
Generate production-ready Flask Cursor rules for Project Rules (.mdc), AGENTS.md, or legacy .cursorrules. This template encodes stack-specific conventions for projects using Flask. Lightweight Python micro-framework with Jinja templates and Werkzeug routing.
The Complete Flask Cursor Rules
The full rule set in all three formats Cursor understands — copy the one your project uses. Project Rules (.mdc) load per-file via globs, AGENTS.md is portable across AI tools, and .cursorrules is the legacy single-file format.
Replacing a legacy file? Read the guide to migrate .cursorrules to Cursor Project Rules (.mdc) before copying this template into your project.
---
description: "Application Factory"
alwaysApply: false
---
- Use the application factory pattern (create_app()).
- Use spaces for indentation.
- Use snake_case for variables and functions.
- Use Blueprints for modular route organization.
- Register extensions in create_app() with init_app() pattern.
- Use app.config.from_object() and from_envvar() for configuration.---
description: "Routes & Views"
alwaysApply: false
---
- Use @bp.route() decorators within Blueprints.
- Use type hints for route parameters (<int:id>, <uuid:id>).
- Use request.get_json() for JSON request bodies.
- Return proper HTTP status codes for all responses.
- Use jsonify() or return dictionaries for JSON responses.
- Use url_for() for generating URLs — never hardcode paths.---
description: "Error Handling"
alwaysApply: false
---
- Use @bp.errorhandler() for route-level error handling.
- Use @app.errorhandler() for application-level error handlers.
- Define custom exception classes with appropriate HTTP status codes.
- Use abort() with status codes for expected error scenarios.
- Log errors with traceback information in production.
- Return structured JSON error responses for API endpoints.---
description: "Database & ORM"
alwaysApply: false
---
- Use SQLAlchemy with Flask-SQLAlchemy extension.
- Define models with explicit column types and constraints.
- Use db.session for transaction management.
- Use Alembic for database migrations (Flask-Migrate).
- Use lazy loading for relationships — eager load with joinedload() when needed.
- Use connection pooling with appropriate pool_size and max_overflow.Customize These Rules
The generator below is preloaded with the Flask template. Adjust indentation, quotes, naming, add your own rules, then download — no need to start from scratch on the homepage.
What This Template Covers
Required guidance
- - Application Factory
- - Routes & Views
- - Error Handling
- - Database & ORM
Default style
- - Indentation: 4 spaces
- - Quotes: double
- - Semicolons: disabled
- - Naming: snake_case
Frequently Asked Questions
- What does the Flask Cursor rules template include?
- It includes 4 rule sections covering application factory, routes & views, error handling and other Flask development conventions.
- Can I generate Flask Project Rules and AGENTS.md from the same template?
- Yes. The generator can export the same stack-specific guidance as modern Project Rules (.mdc), AGENTS.md, or a legacy .cursorrules file.
- Should I combine Flask with other Cursor rules templates?
- Yes. You can combine Flask with related templates such as TypeScript, Tailwind CSS, Docker, or backend frameworks when your project uses multiple technologies.