Development

Flask basic commands

๊ฑด์ด๋‘ 2021. 7. 27. 15:45
728x90

If there is app.py (Flask app), we can run it simply like below.

python3 app.py

However, it is recommended to use Flask own environmental variable to run  Flask app, please see below.

export FLASK_APP=app ๐Ÿ ” Flask app name, it means 'app.py'
export FLASK_ENV=development ๐Ÿ ” We run as developement purpose, otherwise production
export PORT=9010 ๐Ÿ ” Port number to use, normally, 80 port is already taken by running production service
flask run

flask run --reload
๐Ÿ ” As *.py files are updated, flask reload *.py automatically as it detect any updated .py files.

Be carefull, PORT is not default Flask environmental variable, however, please see how to use it below.

if __name__ == '__main__':
    port = os.getenv('PORT', default=9050)
   application.run(host='0.0.0.0', port=port)

Lastly, your Flaks app is ready to launch, we should use gunicorn.

$ gunicorn -w 4 app:application ๐Ÿ ” app means app.py, and application is declared in app.py
728x90