User:Pedro Sá Couto/Prototyping 5th/Flask App/Starting Flask App

From XPUB & Lens-Based wiki

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. 1
https://www.youtube.com/watch?v=BUmUV8YOzgM
https://pythonise.com/series/learning-flask/your-first-flask-app