Lightweight WSGI web framework. Current version is 3.1.3 (Feb 2026). Flask 3.0 (Sep 2023) removed a large set of APIs that had been deprecated since 2.x — before_first_request, FLASK_ENV, JSON config keys, and custom json_encoder/decoder. LLMs still generate these removed patterns.
pip install FlaskVerified import paths — ran on the pinned version, not inferred.
Minimal Flask 3.x app with JSON responses and error handler.
Run initialization code in the app factory, in a CLI command, or using with app.app_context(): at startup. For teardown-based patterns use @app.teardown_appcontext.
Use FLASK_DEBUG=1 or flask run --debug for debug mode. Set app.config['TESTING'] = True for test mode.
Use app.json.sort_keys = False, app.json.mimetype = 'application/json', app.json.ensure_ascii = False on the app.json provider instead.
Subclass flask.json.provider.DefaultJSONProvider and assign: app.json_provider_class = MyProvider, then app = Flask(__name__).
Update send_file calls: send_file(path, download_name='file.csv', max_age=3600, etag=True).
from markupsafe import Markup
flask --app mymodule:app run or export FLASK_APP=mymodule:app
pip install 'Flask[async]' to enable async view support.
Use 'from flask_wtf import FlaskForm' instead of 'from flask import FlaskForm'.
Downgrade Werkzeug to a version before 3.0.0 by adding 'Werkzeug==2.3.7' to your 'requirements.txt' file and reinstalling dependencies.
Import 'escape' from 'markupsafe' instead: 'from markupsafe import escape'.
Ensure that your project structure does not have circular imports and that 'flask' is installed correctly.
Use Python's built-in 'json' module instead: 'import json'.