Part 8 of this project

Middleware

Wrap handlers with before/after hooks

Goal for this part

Wrap handlers with before/after hooks.

Treat 08-Middleware as the source of truth for this checkpoint. If your local tree drifted, re-clone that folder rather than mixing files from neighbors.

What you should already know

You do not need prior Python experience for part 1. Later parts assume you finished the earlier snapshots on the same machine.

  • You can open a terminal and run python3
  • You are comfortable editing a .py file and saving it
  • You do not need a GUI display for this course

Why Python fits Brooklet

Building a tiny framework teaches routing, request objects, and middleware better than only consuming Flask or Django.

There is no window—students curl endpoints and browse HTML the framework renders. Keep the public API small and documented.

Checkpoint

After you run the snapshot, you should recognize the behavior described in the goal—before you move on. If the window (or server) never appears, stop and fix the run steps.

Code shape

Snapshots stay small on purpose. Look for this kind of core call as you read the folder:

@app.route("/hello")
def hello(request):
    return Response("hi")

How to run it

Clone the teaching repo, open 08-Middleware, install what the README asks for, then run python3 app.py.

git clone https://github.com/michaeldunga1/fcc-python-framework.git
cd fcc-python-framework/08-Middleware
# stdlib — no pip packages required for the teaching snapshots
python3 app.py

Common mistakes

  • Hitting the wrong port after an earlier Brooklet process is still running
  • Persisting preferences without a defaults fallback
  • Storing secrets in plain text beside the app
  • Forgetting to reload prefs after a restart