Others


Python - Flask Web Framework


Flask is a lightweight WSGI (Web Server Gateway Interface) web framework . It's a microframework written in Python. It was developed by Armin Ronacher.Flask depends on the Jinja2 template engine and the Werkzeug WSGI toolkit.

What is Werkzeug?

Werkzeug is a extensive (Web Server Gateway Interface) WSGI web application library. It is a full-featured request object with objects to interact with headers, form data, cookies and files.

What is Jinja2?

Jinja2 is a template engine written in Python. It was made after Django’s template. It's used to generate HTML,XML or any markup formats.

<html>
  <head>
    <title>{{data.title}}</title>
  </head>
  <body>
    <ul>
      {% for user in data.userlist %}
        <li>{{user}}</li>
      {% endfor %}
    </ul>
  </body>
</html>

Flask installation

we can install and update flask using pip.

pip install flask

Simple Web Page

app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
	return "<h1>Welcome to Flask</h1>"
	
if __name__=='__main__':
	app.run()

Run the Project:

  1. Run 'app.py' file.
  2. Browse the URL 'localhost:5000'.

Output:

Simple Web Page using Flask