Bird
0
0

Given the following Django view and middleware setup, what will be the value of the X-Frame-Options header in the HTTP response?

medium📝 component behavior Q4 of 15
Django - Security Best Practices
Given the following Django view and middleware setup, what will be the value of the X-Frame-Options header in the HTTP response? ```python # settings.py MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] # views.py from django.http import HttpResponse def my_view(request): response = HttpResponse('Hello') response['X-Frame-Options'] = 'DENY' return response ```
ADENY
BSAMEORIGIN
CALLOW-FROM
DNo X-Frame-Options header
Step-by-Step Solution
Solution:
  1. Step 1: Understand header setting order

    The view sets X-Frame-Options to DENY explicitly on the response.
  2. Step 2: Middleware does not override existing header

    Django's middleware sets the header only if it is not already set by the view.
  3. Final Answer:

    DENY -> Option A
  4. Quick Check:

    View header overrides middleware header = DENY [OK]
Quick Trick: View-set headers override middleware defaults [OK]
Common Mistakes:
MISTAKES
  • Assuming middleware always overwrites headers
  • Confusing SAMEORIGIN as default here
  • Thinking header is missing if set in view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes