Bird
0
0

Why must ALLOWED_HOSTS be explicitly defined in Django's production settings, unlike in development?

hard📝 Conceptual Q10 of 15
Django - Deployment and Production
Why must ALLOWED_HOSTS be explicitly defined in Django's production settings, unlike in development?
ATo allow Django to serve static files directly in production
BTo enable Django's automatic database schema migrations
CTo prevent HTTP Host header attacks by restricting allowed domains
DTo disable Django's built-in CSRF protection
Step-by-Step Solution
Solution:
  1. Step 1: Purpose of ALLOWED_HOSTS

    It restricts which host headers Django will accept to prevent spoofing.
  2. Step 2: Security in production

    Explicitly setting ALLOWED_HOSTS protects against HTTP Host header attacks.
  3. Final Answer:

    To prevent HTTP Host header attacks by restricting allowed domains -> Option C
  4. Quick Check:

    ALLOWED_HOSTS guards against host header attacks [OK]
Quick Trick: ALLOWED_HOSTS protects from host header attacks [OK]
Common Mistakes:
MISTAKES
  • Confusing ALLOWED_HOSTS with static file settings
  • Thinking it controls database migrations
  • Assuming it disables CSRF protection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes