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

From XPUB & Lens-Based wiki
No edit summary
 
Line 58: Line 58:
<br><br><br><br>
<br><br><br><br>
<pre>
<pre>
Building your first Flask app - Python on the web - Learning Flask series Pt. 2
Building your first Flask app - Python on the web - Learning Flask series Pt. 1
https://www.youtube.com/watch?v=-BC3V1CUKpU&t=44s
https://www.youtube.com/watch?v=BUmUV8YOzgM
https://pythonise.com/series/learning-flask/flask-application-structure
https://pythonise.com/series/learning-flask/your-first-flask-app
</pre>
</pre>

Latest revision as of 22:28, 31 March 2020

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