Django - Deployment and ProductionYou 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 customizationBAdd headers in Django views serving static filesCModify STATIC_URL to include headersDSubclass WhiteNoise and override the add_headers methodCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand WhiteNoise customizationWhiteNoise allows customization by subclassing and overriding methods like add_headers to add custom headers.Step 2: Evaluate other optionsStatic files are not served by views, STATIC_URL is a URL path, and DEBUG does not control headers.Final Answer:Subclass WhiteNoise and override the add_headers method -> Option DQuick Check:Custom headers = subclass WhiteNoise [OK]Quick Trick: Override add_headers in WhiteNoise subclass for custom headers [OK]Common Mistakes:MISTAKESTrying to add headers in views for static filesChanging STATIC_URL expecting headers
Master "Deployment and Production" in Django9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Django Quizzes Async Django - When async helps and when it does not - Quiz 7medium Async Django - Why async matters in Django - Quiz 3easy Caching - Cache backends (memory, Redis, Memcached) - Quiz 14medium DRF Advanced Features - Custom serializer fields - Quiz 6medium DRF Advanced Features - Serializer validation - Quiz 9hard Deployment and Production - Database migration in production - Quiz 4medium Django REST Framework Basics - Serializers for data conversion - Quiz 13medium Security Best Practices - Security checklist (manage.py check --deploy) - Quiz 2easy Security Best Practices - Content Security Policy - Quiz 6medium Testing Django Applications - TestCase and SimpleTestCase - Quiz 12easy