User:Pedro Sá Couto/Prototyping 5th/Flask App/Starting Flask App: Difference between revisions
No edit summary |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
<pre style="color: silver; background: black;"> | <pre style="color: silver; background: black;"> | ||
$ sudo touch app.py | $ sudo touch app.py | ||
</pre> | |||
===04 Open app.py=== | |||
<pre style="color: silver; background: black;"> | |||
$ vim app.py | |||
</pre> | |||
===05 Simple Hello world app=== | |||
<source lang="python"> | |||
from flask import Flask | |||
app = Flask(__name__) | |||
@app.route("/") | |||
def index(): | |||
return "Hello world!" | |||
if __name__ == "__main__": | |||
app.run() | |||
</source> | |||
===06 Export app=== | |||
<pre style="color: silver; background: black;"> | |||
$ export FLASK_APP=app.py | |||
</pre> | |||
===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 | |||
<pre style="color: silver; background: black;"> | |||
$ export FLASK_ENV=development | |||
$ FLASK_ENV=development | |||
</pre> | |||
===08 Run the app outside localhost, otherwise you would only see it in the Pi=== | |||
<pre style="color: silver; background: black;"> | |||
$ flask run --host=0.0.0.0 | |||
</pre> | |||
<br><br><br><br> | |||
<pre> | |||
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 | |||
</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