Maki
Maki

Reputation: 479

Flask - converting python execution to flask run

I developed my first flask application that is currently running and everything work fine. The application is loaded using "python application.py" or using gUnicorn. There is no fancy fancy folder structure everything is in the same folder, with exception of the static\ and templates\

Folder Structure:

- application\hello.py
- application\static\
- application\templates\

To Run: - python hello.py

    #hello.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', load_dotenv=True, debug=True, threaded=True)

Now that looking to add more functionalities to the application noticed most tutorials uses "flask run" to launch the instead. There are two different tutorials I am following one using blueprints and the other one is the microblog tutorial both using similar folder structure:

- application\run.py
- application\app\main.py
- application\app\static\
- application\app\templates\

To run: - export Flask_APP=run.py - flask run

The application will continue to grow and I want to follow best practices.

Question 1: How do I enable the following parameters when using "flask run"??:

if __name__ == '__main__':
        app.run(host='0.0.0.0', load_dotenv=True, debug=True, threaded=True)

Question 2: Is there any pro/cons configuring the app to run using flask run vs python app.py????? There was another post with this title but context was unrelated.

When can I read more about this??

Upvotes: 0

Views: 747

Answers (1)

abdusco
abdusco

Reputation: 11061

Threaded mode is enabled by default. You don't have to pass it in. Source

  1. For debug mode, use export FLASK_DEBUG=1. Source
  2. For load_dotenv use export FLASK_SKIP_DOTENV=0 Source
  3. For specifying port use export FLASK_RUN_PORT=8000. Source
  4. To bind the app to 0.0.0.0, set SERVER_NAME config like app.config['SERVER_NAME']. Source

Also see: http://flask.pocoo.org/docs/1.0/cli/#setting-command-options

Upvotes: 1

Related Questions