flask
Run and manage Flask web applications
TLDR
Run a development server
Show the routes for the app
Run a Python interactive shell in the app's context
SYNOPSIS
flask [OPTIONS] COMMAND [ARGS]...
PARAMETERS
--app PATH
Specify the Python path to the Flask application. This can be a module name (e.g., my_app), a factory function (e.g., my_app:create_app), or a file path (e.g., app.py). Overrides the FLASK_APP environment variable.
--env ENV
Set the Flask environment. Common values are development or production. This influences debug mode and other configuration settings. Overrides the FLASK_ENV environment variable.
--debug
Enable debug mode. This activates the interactive debugger and auto-reloader, useful for development. Implied when FLASK_ENV is set to development.
--no-debug
Disable debug mode explicitly. Useful if FLASK_ENV is development but you want to disable debug for a specific run.
--version
Show the Flask framework version and exit.
--help
Show a help message for the flask command or a specific subcommand. For example, flask run --help.
DESCRIPTION
The flask command is the command-line interface (CLI) tool for the Flask web framework, a popular Python microframework used for building web applications. Unlike traditional Linux commands that are part of the operating system, flask is a Python executable that gets installed when you install the Flask framework via pip.
Its primary purpose is to assist developers in managing their Flask applications during development. Common uses include running a development server, opening an interactive shell for debugging, showing application routes, and managing database migrations or other application-specific tasks defined by the developer. The exact behavior of the flask command often depends on environment variables like FLASK_APP and FLASK_ENV, which tell the command how to locate and configure the Flask application.
CAVEATS
The flask command is not a built-in Linux utility. It requires Python and the Flask framework to be installed, typically within a virtual environment. Its functionality heavily depends on the configuration of your Flask application, particularly the FLASK_APP environment variable or the --app option, which tells the command where to find your application instance. Without proper configuration, the command may fail to locate your application.
IMPORTANT ENVIRONMENT VARIABLES
The behavior of the flask command is heavily influenced by environment variables, which define the context for your Flask application:
FLASK_APP: Specifies the import path to your Flask application instance (e.g., my_app.py or my_app:create_app()). This is crucial for the flask command to locate and load your application.
FLASK_ENV: Defines the environment in which the application is running, typically development or production. This affects configuration settings, error handling, and debug mode. Setting it to development automatically enables debug mode and the reloader.
COMMON SUBCOMMANDS
While the flask command takes global options, its main power comes from its subcommands, each with its own set of options and arguments:
flask run: Runs the development server. This is the most common subcommand, allowing you to view and interact with your application in a web browser.
flask shell: Opens an interactive Python shell with your application context loaded, allowing you to access database models, configurations, and other application components directly.
flask routes: Displays a table of all registered URL rules (routes) for your application, including their associated endpoints and methods.
Developers can also define custom subcommands for their specific application needs, making the flask CLI extensible.
HISTORY
The Flask framework was created by Armin Ronacher and first released in 2010. Initially, running Flask applications often involved direct Python scripts. The dedicated flask command-line interface was introduced later to provide a more unified and user-friendly experience for common development tasks, standardizing the way developers interact with their Flask projects. It has evolved to include various subcommands for common operations like running the development server (run), entering an interactive shell (shell), and listing routes (routes).
SEE ALSO
python(1), pip(1), virtualenv(1), gunicorn(1)