Recall & Review
beginner
What is middleware in Flask?
Middleware in Flask is a piece of code that runs before or after the main request handler. It can modify requests or responses, like a helpful assistant checking or changing things as they pass through.
Click to reveal answer
intermediate
How do you create custom middleware in Flask?
You create a class with a __call__ method that takes the WSGI environment and start_response function. Inside, you can add your code before or after calling the next app in the chain.Click to reveal answer
intermediate
What does the __call__ method do in Flask middleware?
The __call__ method makes the middleware class behave like a function. Flask calls it with request details, letting your middleware process or change the request or response.Click to reveal answer
beginner
Why use middleware in a Flask app?
Middleware helps add features like logging, authentication, or modifying requests without changing your main app code. It keeps your app clean and organized.
Click to reveal answer
intermediate
How do you add your custom middleware to a Flask app?
Wrap your Flask app with your middleware class when creating the app. For example, app.wsgi_app = YourMiddleware(app.wsgi_app). This tells Flask to use your middleware.Click to reveal answer
What method must a Flask middleware class implement to be callable?
✗ Incorrect
The __call__ method allows the middleware class to be called like a function by Flask.
Where do you insert your middleware in a Flask app?
✗ Incorrect
Middleware wraps the app's wsgi_app attribute to intercept requests and responses.
What can middleware modify in Flask?
✗ Incorrect
Middleware can modify the incoming requests or outgoing responses.
Which of these is NOT a typical use of middleware?
✗ Incorrect
Rendering HTML templates is done in route handlers, not middleware.
What arguments does the __call__ method in Flask middleware receive?
✗ Incorrect
The __call__ method receives the WSGI environ dictionary and start_response function.
Explain how to create and add custom middleware to a Flask app.
Think about how middleware acts like a filter around your app.
You got /4 concepts.
Describe three common uses of middleware in Flask applications.
Middleware helps with tasks before or after your main app runs.
You got /3 concepts.