Project 7: Build Flask (Minimal Microframework)

Build a tiny Flask-like framework with routing, templates, and request context.


Quick Reference

Attribute Value
Difficulty Intermediate
Time Estimate 2 weeks
Language Python
Prerequisites WSGI basics, decorators
Key Topics routing, request context, templating
Output Microframework + demo app

Learning Objectives

By completing this project, you will:

  1. Implement Flask-style @route decorators.
  2. Build a request context using contextvars.
  3. Render templates with context variables.
  4. Add a dev server and error handlers.
  5. Explain microframework design trade-offs.

The Core Question You’re Answering

“What is the smallest ergonomic API for web development?”


Concepts You Must Understand First

Concept Why It Matters Where to Learn
Context locals Flask request globals Flask docs
Decorator routing Register handlers Python docs
Template rendering Separate logic and UI Jinja2 docs

Project Specification

Functional Requirements

  1. Define @app.route decorator.
  2. Support path params and methods.
  3. Provide request proxy (args/form/headers).
  4. Render templates with Jinja2.
  5. Return proper responses and status codes.

Implementation Guide

Project Structure

project-root/
├── microflask/
│   ├── app.py
│   ├── routing.py
│   ├── context.py
│   └── templating.py
└── demo.py

Questions to Guide Your Design

  1. How will you avoid global state issues?
  2. How will you parse request data once?
  3. How will you add error handling?

Testing Strategy

  • Routes map correctly.
  • Request context is per-request.
  • Templates render with variables.

Extensions

  • Add sessions.
  • Add blueprint routing.
  • Add JSON helpers.

This guide was generated from LEARN_DJANGO_WEB_FRAMEWORKS.md. For the complete learning path, see the parent directory LEARN_DJANGO_WEB_FRAMEWORKS/README.md.