How do I launch the app with a flask?

I want to know the correct way to launch a flash application. The docs show two different commands:

$ flask -a sample run

      

and

$ python3.4 sample.py 

      

will give the same result and run the application correctly.

What is the difference between the two and which should be used to run a Flask application?

+10


source to share


2 answers


The executable flask

is a simple command line launcher for Flask applications. This was introduced in Jar 0.11. It replaces the Flask-Script extension for adding commands. The docs describe how to use and add commands for this.

The command python sample.py

runs the Python file and installs __name__ == "__main__"

. If the main block calls app.run()

, it will start the development server. You have no way to change the arguments to run

when you call it.



Both of these commands end up running the Werkzeug development server , which, as the name suggests, runs a simple HTTP server that should only be used during development. You should prefer using command flask run

over method app.run()

.

+14


source


The latest documentation contains the following example:

Unix Bash (Linux, Mac, etc.):

$ export FLASK_APP=hello
$ flask run

      



Windows CMD:

> set FLASK_APP=hello
> flask run

      

+3


source







All Articles