Difference between revisions of "Flask"
Jump to navigation
Jump to search
m (→templates=) |
(→basics) |
||
Line 1: | Line 1: | ||
=basics= | =basics= | ||
− | https://flask.palletsprojects.com/en/1.1.x/quickstart/ | + | Check this[https://flask.palletsprojects.com/en/1.1.x/quickstart/] |
+ | Hello world app: | ||
+ | <syntaxhighlight lang=python> | ||
+ | #!/usr/bin/env python3 | ||
+ | |||
+ | from flask import Flask | ||
+ | print(__name__) | ||
+ | app = Flask(__name__) | ||
+ | |||
+ | @app.route('/') | ||
+ | |||
+ | def main(): | ||
+ | return 'Hello World' | ||
+ | |||
+ | if __name__ == '__main__': | ||
+ | app.run() | ||
+ | </syntaxhighlight> | ||
+ | Run the build-in server listening to all | ||
+ | <syntaxhighlight lang=bash> | ||
+ | export FLASK_APP=welcome_app.py | ||
+ | flask run --host=0.0.0.0 | ||
+ | </syntaxhighlight> | ||
+ | welcome_app | ||
+ | * Serving Flask app "welcome_app" | ||
+ | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) | ||
+ | |||
+ | Now you can browse to <serverIP>:5000 | ||
https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972 | https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972 | ||
− | |||
=templates= | =templates= |
Revision as of 21:03, 9 February 2020
basics
Check this[1]
Hello world app:
#!/usr/bin/env python3
from flask import Flask
print(__name__)
app = Flask(__name__)
@app.route('/')
def main():
return 'Hello World'
if __name__ == '__main__':
app.run()
Run the build-in server listening to all
export FLASK_APP=welcome_app.py
flask run --host=0.0.0.0
welcome_app * Serving Flask app "welcome_app" * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Now you can browse to <serverIP>:5000 https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972
templates
https://flask.palletsprojects.com/en/1.1.x/patterns/templateinheritance/#template-inheritance