User:Pedro Sá Couto/Prototyping 5th/Flask App/Starting Flask App
< User:Pedro Sá Couto | Prototyping 5th
Revision as of 21:27, 31 March 2020 by Pedro Sá Couto (talk | contribs) (→07 Change Flask environment)
Starting Flask App
01 Activate the created Virtual Environment
$ source venv/bin/activate
02 Check installed packages
$ pip list
03 Create your app
$ sudo touch app.py
04 Open app.py
$ vim app.py
05 Simple Hello world app
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello world!"
if __name__ == "__main__":
app.run()
06 Export app
$ export FLASK_APP=app.py
07 Change Flask environment
Difference between development and production You do not want to run the development environment on a server that is running, because it gives debugging information, it is not safe
$ export FLASK_ENV=development $ FLASK_ENV=development
08 Run the app outside localhost, otherwise you would only see it in the Pi
$ flask run --host=0.0.0.0
Building your first Flask app - Python on the web - Learning Flask series Pt. 2 https://www.youtube.com/watch?v=-BC3V1CUKpU&t=44s https://pythonise.com/series/learning-flask/flask-application-structure