Middleware must accept the app in __init__ and implement __call__ with environ and start_response.
Step 2: Validate options
Only class MyMiddleware:
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
return self.app(environ, start_response) matches this pattern correctly. Others miss __call__ or parameters.
Final Answer:
Correct middleware class with __init__ and __call__ methods -> Option A
Quick Check:
Middleware class needs __call__ method [OK]
Quick Trick:Middleware class must implement __call__(environ, start_response) [OK]
Common Mistakes:
MISTAKES
Omitting __call__ method
Not passing app to __init__
Using function instead of class
Master "Middleware and Extensions" in Flask
9 interactive learning modes - each teaches the same concept differently