Difference between revisions of "Flask"

From wiki
Jump to navigation Jump to search
Line 37: Line 37:
  
 
=Integrate with nginx=
 
=Integrate with nginx=
 +
https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/

Revision as of 23:17, 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()  # Default (listen to localhost port 5000, use flash run for options)
    #app.run(host='0.0.0.0',port=8080,Debug=True)  # Run in debug mode, listen to all hosts on port 8080

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

Integrate with nginx

https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/