Skip to content

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 to app.pyapp.py module)
  • 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 run
export FLASK_APP=app
flask run

Useful built-in commands

  • flask runflask run — run dev server
  • flask 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-admin
  • flask 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_APP is 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 coffee

Was this page helpful?

Let us know how we did