Home / Flask / Introduction

Flask Tutorial

Flask is a lightweight Python micro-framework. It gives you the core tools and lets you choose your own libraries — perfect when you want full control without the opinions of a full-stack framework.

Flask vs Django

FeatureFlaskDjango
SizeMicro (minimal)Full stack (batteries included)
ORMYour choice (SQLAlchemy)Built-in Django ORM
AdminFlask-Admin (optional)Auto-generated admin
FlexibilityVery highOpinionated structure
Best forMicroservices, small APIs, custom appsLarge full-stack apps
Python – Flask Core Concepts
# Simulating Flask routing and request handling
from functools import wraps

class Flask:
    def __init__(self, name):
        self.name    = name
        self.routes  = {}
        self.filters = {}
        self.before_req = []

    def route(self, path, methods=None):
        def decorator(fn):
            m = tuple(methods or ["GET"])
            self.routes[(path, m)] = fn
            return fn
        return decorator

    def before_request(self, fn):
        self.before_req.append(fn); return fn

    def dispatch(self, path, method="GET", **kwargs):
        for _ in self.before_req: _()
        for (p, m), fn in self.routes.items():
            if p == path and method in m:
                return fn(**kwargs)
        return ("404 Not Found", 404)

app = Flask(__name__)

@app.before_request
def log_request():
    print("[LOG] Request received")

@app.route("/")
def index():
    return ("Welcome to Flask!", 200)

@app.route("/users", methods=["GET", "POST"])
def users():
    return ([{"id": 1, "name": "Alice"}], 200)

print(app.dispatch("/"))
print(app.dispatch("/users"))
print(app.dispatch("/missing"))
Try It – Flask Routing
Python
Code Editor
Output
Click ▶ Run…
Quick Quiz

What is the name of Flask's built-in templating engine?


Flask Coding Labs

8 hands-on labs from basic routing to REST APIs and testing.

Lab 1 – REST API with JSON

Flask REST API Lab
Python
Code Editor
Output
Click ▶ Run…

Lab 2 – Blueprint Pattern

Flask Blueprints Lab
Python
Code Editor
Output
Click ▶ Run…