Bird
0
0

If you deploy a Django app with DEBUG=False but leave ALLOWED_HOSTS empty, what response will the server return when accessed?

medium📝 Debug Q6 of 15
Django - Deployment and Production
If you deploy a Django app with DEBUG=False but leave ALLOWED_HOSTS empty, what response will the server return when accessed?
A500 Internal Server Error due to missing settings
B400 Bad Request error due to host header validation failure
C200 OK with default host fallback
DRedirect to the Django admin login page
Step-by-Step Solution
Solution:
  1. Step 1: Role of ALLOWED_HOSTS

    ALLOWED_HOSTS restricts which host headers Django accepts.
  2. Step 2: Effect of empty ALLOWED_HOSTS with DEBUG=False

    Requests to any host will be rejected with a 400 error.
  3. Final Answer:

    400 Bad Request error due to host header validation failure -> Option B
  4. Quick Check:

    Empty ALLOWED_HOSTS causes 400 error [OK]
Quick Trick: Empty ALLOWED_HOSTS + DEBUG=False = 400 error [OK]
Common Mistakes:
MISTAKES
  • Expecting 500 error instead of 400
  • Assuming Django serves requests regardless
  • Thinking it redirects to login

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes