Bird
0
0

Which of the following is the correct way to wrap a Flask app with a custom middleware class named MyMiddleware?

easy📝 Syntax Q3 of 15
Flask - Middleware and Extensions
Which of the following is the correct way to wrap a Flask app with a custom middleware class named MyMiddleware?
Aapp.middleware = MyMiddleware(app)
Bapp.wsgi_app = MyMiddleware(app.wsgi_app)
CMyMiddleware(app)
Dapp = MyMiddleware(app)
Step-by-Step Solution
Solution:
  1. Step 1: Understand Flask middleware wrapping

    Middleware wraps the WSGI app via app.wsgi_app attribute.
  2. Step 2: Check options

    Only app.wsgi_app = MyMiddleware(app.wsgi_app) correctly assigns MyMiddleware wrapping to app.wsgi_app.
  3. Final Answer:

    app.wsgi_app = MyMiddleware(app.wsgi_app) -> Option B
  4. Quick Check:

    Wrap middleware on app.wsgi_app [OK]
Quick Trick: Wrap middleware on app.wsgi_app attribute [OK]
Common Mistakes:
MISTAKES
  • Assigning middleware to app directly
  • Not wrapping app.wsgi_app
  • Calling middleware without assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes