Flask: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 3: Line 3:
<br />
<br />


= Basics =
Source: [https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world blog.miguelgrinberg.com]
Source: [https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world blog.miguelgrinberg.com]


Line 8: Line 9:
pip3 install flask
pip3 install flask


Hello World:
== Hello World ==
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
from flask import Flask
from flask import Flask
Line 21: Line 22:
</syntaxhighlight>
</syntaxhighlight>


Access the above app from:
*Access the above app from:
http://127.0.0.1:5000/
http://127.0.0.1:5000/


== Opions ==
Enable Debugging:

*All parameters are optional:
app.run(host, port, debug, options)

host: Hostname to listen on. Defaults to 127.0.0.1 (localhost). Set to ‘0.0.0.0’ to have server available externally
port: Defaults to 5000
debug: Defaults to false. If set to true, provides a debug information
options: To be forwarded to underlying Werkzeug server.

*Enable Debugging:
app.debug = True
app.debug = True


Access URL over network with custom port:
*Access URL over network with custom port:
app.run(host = '0.0.0.0',port=5005)
app.run(host = '0.0.0.0',port=5005)