Bird
0
0

Which Flask feature is commonly used to add secure headers to every response?

easy📝 Conceptual Q11 of 15
Flask - Security Best Practices
Which Flask feature is commonly used to add secure headers to every response?
AThe <code>@app.before_first_request</code> decorator
BThe <code>@app.route</code> decorator
CThe <code>@app.after_request</code> decorator
DThe <code>@app.teardown_request</code> decorator
Step-by-Step Solution
Solution:
  1. Step 1: Understand Flask request lifecycle

    Flask allows modifying responses after the view function runs using @app.after_request.
  2. Step 2: Identify where headers are added

    Secure headers are added to the response object, which is accessible in @app.after_request.
  3. Final Answer:

    The @app.after_request decorator -> Option C
  4. Quick Check:

    Use @app.after_request to add headers [OK]
Quick Trick: Add headers in @app.after_request for all responses [OK]
Common Mistakes:
MISTAKES
  • Using @app.route which only defines routes
  • Trying to add headers in @app.before_first_request which runs once
  • Using @app.teardown_request which is for cleanup, not response modification

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes