When you're working with Flask, a popular Python web framework, you'll often need to run your application to see it in action. The command to do this is simple: `flask run`. But there's more to it than just that. Let's dive into the details of running a Flask app, including common options and best practices.
Understanding the `flask run` Command
The `flask run` command is the primary way to start your Flask application. It's a convenient wrapper around the `FLASK_APP` environment variable and the `flask` command-line tool. Here's a basic breakdown:
FLASK_APPis an environment variable that points to your Flask application's entry point. It's usually set to the name of your application's module, likemyapp.- The
flaskcommand-line tool is a script that comes with Flask. It uses theFLASK_APPvariable to find and run your application.
Running Your Flask App
To run your Flask app, simply open your terminal, navigate to your project's root directory (where your app.py or __init__.py file is located), and type:
![Learn Flask [2026] Most Recommended Tutorials](https://i.pinimg.com/originals/70/c3/0b/70c30b834f681afe86155783ec72f112.png)
flask run
This will start your application and display a URL where you can access it. By default, it will be something like http://127.0.0.1:5000/.
Using the `--host` and `--port` Options
You can customize the host and port used by your Flask app with the `--host` and `--port` options. For example, to run your app on localhost with a custom port of 8000, you would use:
flask run --host=localhost --port=8000
Using Environment Variables
You can also set the host and port using environment variables. This can be useful if you're running your app in a production environment where you might not have access to the command line. Here's how you can do it:

- Set the
FLASK_HOSTenvironment variable to the host you want to use. - Set the
FLASK_PORTenvironment variable to the port you want to use.
Then, simply run flask run as usual.
Running Your Flask App in Debug Mode
By default, Flask runs in debug mode when you use the `flask run` command. This means that it will automatically reload the server when you make changes to your code and provide a helpful debugger and debugger console. However, it's not recommended to run your app in debug mode in a production environment due to security risks.
Disabling Debug Mode
To disable debug mode, you can use the `--no-debugger` and `--no-reload` options:

flask run --no-debugger --no-reload
Alternatively, you can set the FLASK_ENV environment variable to production to disable debug mode:
export FLASK_ENV=production
Running Your Flask App with Gunicorn
While the `flask run` command is great for development, it's not recommended for production use. For production, you should use a WSGI server like Gunicorn. Here's how you can do it:
- Install Gunicorn if you haven't already:
pip install gunicorn - Run your app with Gunicorn:
gunicorn app:app
This will start your app using Gunicorn, which is more suitable for production use.
Conclusion
Running a Flask app is a straightforward process, but there are many options and best practices to consider. Whether you're just starting out or you're a seasoned Flask developer, understanding the `flask run` command and its various options can help you work more efficiently and effectively.






















