Bird
0
0

You added ProfilerMiddleware but see no profiling output. What is the most likely mistake in this code?

medium📝 Debug Q14 of 15
Flask - Performance Optimization
You added ProfilerMiddleware but see no profiling output. What is the most likely mistake in this code?
from flask import Flask
from werkzeug.middleware.profiler import ProfilerMiddleware
app = Flask(__name__)
app = ProfilerMiddleware(app, restrictions=[10])

@app.route('/')
def index():
    return 'Test'
AFlask app must be run with debug=True for profiling
BMissing import of ProfilerMiddleware
CRestrictions list must be empty
DProfilerMiddleware should wrap app.wsgi_app, not app directly
Step-by-Step Solution
Solution:
  1. Step 1: Check how ProfilerMiddleware is applied

    It incorrectly wraps app instead of app.wsgi_app.
  2. Step 2: Correct usage for profiling

    ProfilerMiddleware must wrap app.wsgi_app to work properly.
  3. Final Answer:

    ProfilerMiddleware should wrap app.wsgi_app, not app directly -> Option D
  4. Quick Check:

    Wrap app.wsgi_app, not app [OK]
Quick Trick: Always wrap app.wsgi_app with ProfilerMiddleware [OK]
Common Mistakes:
MISTAKES
  • Wrapping app instead of app.wsgi_app
  • Forgetting to import ProfilerMiddleware
  • Misconfiguring restrictions parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes