Flask Cheat Sheet
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
A single-page, colour-coded summary of the Flask essentials, written against Flask 3.1.3, Werkzeug 3.1.9 and
Python 3.10+ (versions verified 2026-10-07) — how to install and run an app (flask --app ... run --debug and
.flaskenv), the application factory and project layout, the configuration loaders and the key settings, the two
contexts and the order of the request lifecycle, routing, converters and url_for, request data, responses and
JSON, error handlers and hooks, blueprints, Jinja essentials, sessions and flashing, Flask-WTF and CSRF,
Flask-SQLAlchemy 2.0-style queries with db.paginate, Flask-Migrate commands, Flask-Login and Flask-JWT-Extended,
the security settings (SECRET_KEY_FALLBACKS, TRUSTED_HOSTS, cookie flags and request limits), the flask-smorest
decorators, the CLI and signals, the Celery pattern, async, gevent and Quart, streaming and Server-Sent Events,
pytest fixtures, Gunicorn, Waitress, nginx and ProxyFix, and a strip of what changed since older tutorials and
books, with a table mapping each outdated idiom to the current code — handy for quick memorization or as a
downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — Python Flask.
Foundations — Introduction & Architecture, Getting Started, Application Factory & Project Layout, Configuration, and Application & Request Lifecycle.
Routing, views and requests — Routing & URL Building, Request Data, Responses & JSON, Error Handling, Class-based Views, Hooks & View Decorators, and Blueprints.
Templates, sessions, forms and files — Jinja Templates, Static Files & Assets, Sessions, Cookies & Flashing, Forms with Flask-WTF, and File Uploads.
Data — SQLite3 and Database Basics, Flask-SQLAlchemy, Database Migrations, and NoSQL, Redis, MongoDB & Search.
Authentication, authorization and security — Authentication & Flask-Login, OAuth Social Login & LDAP, Authorization & Roles, and Security Considerations.
Building APIs — Building REST APIs, OpenAPI & API Documentation, JWT & API Authentication, and Single-Page Apps & CORS.
Extensions and ecosystem — Extensions & Ecosystem, CLI & Shell, Signals, Admin Interfaces with Flask-Admin, Internationalization with Flask-Babel, Caching, and Background Jobs, Celery & Email.
Async, streaming and real-time — Async, gevent & Quart and Streaming & Server-Sent Events.
Testing and debugging — Testing, API Contract & Property-based Testing, and Debugging, Logging & Profiling.
Production — Deployment: WSGI Servers & Proxies, Docker & Kubernetes, and Cloud Platforms & Monitoring.
Beyond the basics — Integrating LLM APIs and What’s Changed & Migration.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.