February 08, 2018

Flask - Python module

❑ Flask is a module for webdevelop in Python.

❑ An instance of the Flask class in the flask module is a WSGI application.
* WSGI(Web Server Gateway Interface) : Because it is produced at a low level, there is no wall between the web server, the web app, and the framework.


<main.py>
from flask import Flask
app = Flask(__name__)

@app.route(‘/hello’)
def hello():         
    return render_template(‘hello.html’, name=name)

app.run(host=’x.x.x.x’, port=8080, debug=True) 

❑ @app.route(‘/hello’) : Route decorator.
* Route decorator : It tells to Flask that the server will run the following function when someone connects to with the "/hello" URL:

❑ return render_template(‘hello.html’, name=name) : Load "hello.html" that is in [Path of main.py]/templates/[File name].

❑ app.run(host=’x.x.x.x’, port=8080, debug=True) : Drive the server.
* debug = True : When it set, a separate thread of debug mode is run. When code change is detected, server is automatically restarted.

❑ Flask uses Jinja2 as the template engine.

※ Flask document(Link)