Bird
0
0

You want to serve static files with WhiteNoise and also add custom headers for security. How can you do this?

hard📝 Application Q8 of 15
Django - Deployment and Production
You want to serve static files with WhiteNoise and also add custom headers for security. How can you do this?
ASet DEBUG = True to enable header customization
BAdd headers in Django views serving static files
CModify STATIC_URL to include headers
DSubclass WhiteNoise and override the add_headers method
Step-by-Step Solution
Solution:
  1. Step 1: Understand WhiteNoise customization

    WhiteNoise allows customization by subclassing and overriding methods like add_headers to add custom headers.
  2. Step 2: Evaluate other options

    Static files are not served by views, STATIC_URL is a URL path, and DEBUG does not control headers.
  3. Final Answer:

    Subclass WhiteNoise and override the add_headers method -> Option D
  4. Quick Check:

    Custom headers = subclass WhiteNoise [OK]
Quick Trick: Override add_headers in WhiteNoise subclass for custom headers [OK]
Common Mistakes:
MISTAKES
  • Trying to add headers in views for static files
  • Changing STATIC_URL expecting headers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes