Flask

Flask is a lightweight WSGI web application framework designed to make getting started quick and easy

Overview

Flask is a microframework that provides the essentials for web development without imposing dependencies or project layout

Key Features

Minimal Core

Flask keeps the core simple and extensible

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

Jinja2 Templating

Powerful template engine

from flask import render_template

@app.route('/user/<name>')
def user(name):
    return render_template('user.html', name=name)

URL Building

Generate URLs for routes

from flask import url_for

url = url_for('user', name='John')

Request Handling

Access request data easily

from flask import request

@app.route('/login', methods=['POST'])
def login():
    username = request.form['username']
    password = request.form['password']
    return f'Logged in as {username}'

Extensions

Flask extensions add functionality

Installation

pip install flask

Common Use Cases

Advantages

Disadvantages

Official Documentation

Flask Documentation

Version Information