Bird
0
0

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

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

    WSGI middleware wraps the Flask app by passing the app instance to the middleware constructor.
  2. Step 2: Match correct syntax

    The correct syntax is assigning the wrapped app back to app using app = MyMiddleware(app).
  3. Final Answer:

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

    Wrap app by passing it to middleware constructor [OK]
Quick Trick: Wrap app by calling middleware with app as argument [OK]
Common Mistakes:
MISTAKES
  • Calling middleware as a method on app
  • Not assigning wrapped app back to a variable
  • Assigning middleware class without instantiation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes