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:
- Implement Flask-style
@routedecorators. - Build a request context using contextvars.
- Render templates with context variables.
- Add a dev server and error handlers.
- 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
- Define
@app.routedecorator. - Support path params and methods.
- Provide
requestproxy (args/form/headers). - Render templates with Jinja2.
- 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
- How will you avoid global state issues?
- How will you parse request data once?
- 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.