Flask 3 cheatsheet
Flask 3: Setup and CLI
7 common Flask 3 tasks.
Hello world app
The smallest Flask application, saved as app.py.
from flask import Flask
app = Flask(__name__)
@app.get("/")
def index():
return "Hello, World!"
Run the development server
Start the app with the debugger and auto-reload. Never use debug mode in production.
flask --app app run --debug
Run on another host or port
Listen on all interfaces on port 8000.
flask --app app run --host 0.0.0.0 --port 8000
Open a shell with the app loaded
Start a Python shell with the application context active.
flask --app app shell
Add a CLI command
Add your own command, run with flask --app app seed.
@app.cli.command("seed")
def seed():
"""Load sample data."""
print("Seeded")