Flask Command Line Interface (CLI)
Flask includes a CLI (built on Click) that makes development workflows smooth.
How the Flask CLI finds your app
The CLI needs to know what Flask application to run.
Common ways:
FLASK_APP=appFLASK_APP=app(points toapp.pyapp.pymodule)FLASK_APP=package:create_appFLASK_APP=package:create_app(factory pattern)
Example
If you have app.pyapp.py with app = Flask(__name__)app = Flask(__name__):
export FLASK_APP=app
flask runexport FLASK_APP=app
flask runUseful built-in commands
flask runflask run— run dev serverflask routesflask routes— list all routes (very helpful!)flask shellflask shell— open a Python shell with app context (commonly used in bigger apps)
Adding custom commands (preview)
Later, you can add custom commands like:
flask create-adminflask create-adminflask seed-dbflask seed-db
Typically you’ll register them through the app factory or extensions.
Troubleshooting
If you see errors like:
- “Could not locate a Flask application”
It usually means:
FLASK_APPFLASK_APPis not set- your import path is wrong
- you’re in the wrong working directory
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
