Home > Article > Backend Development > Flask App Startup: `flask run` vs. `python3.4 sample.py` - Which is Better?
How to Run a Flask Application: A Comparison of Approaches
Flask offers two primary methods for starting an application: the flask command and the python3.4 sample.py command. While both commands accomplish the same goal, there are nuanced differences and best practices associated with each.
The flask Command
The flask command serves as a command-line interface (CLI) specifically designed for interacting with Flask applications. One of its features is the flask run command, which is the recommended approach for launching the development server.
Usage:
$ flask --app sample --debug run
Benefits:
The python3.4 sample.py Command
This command simply runs the specified Python file, which typically contains the code for your Flask application. If the __main__ block calls app.run(), the development server will be launched.
Usage:
$ python3.4 sample.py
Considerations:
Recommendation:
In general, using the flask run command is the preferred and recommended approach for starting a Flask application in development. It provides a centralized and convenient way to manage the application and configure settings. If specific customization or direct code execution is necessary, the python3.4 sample.py command remains a valid option.
The above is the detailed content of Flask App Startup: `flask run` vs. `python3.4 sample.py` - Which is Better?. For more information, please follow other related articles on the PHP Chinese website!