Why is it a security risk to keep DEBUG = True in a production environment?
Last updated
With DEBUG = True, Django exposes detailed error pages and internal behavior intended only for developers; in production this leaks sensitive information and weakens protections, handing attackers a roadmap to your system.
Information disclosure:
Unhandled exceptions render full tracebacks with source code, local variable values, and the SQL being run.
Settings are shown (with some keys masked, but much context exposed), revealing structure attackers can exploit.
Weakened host protection: When
DEBUGis True,ALLOWED_HOSTSvalidation is effectively bypassed, enabling Host header attacks.Memory and performance: Django stores every executed query in memory for debugging, which leaks memory over a long-running process.
Correct setup: Set
DEBUG = False, configureALLOWED_HOSTS, and provide custom404/500templates plus real logging.
- https://www.geeksforgeeks.org/python/django-interview-questions/
- https://foysalff.medium.com/12-advanced-django-interview-questions-for-experienced-developers-dbe654e21a45
- https://www.careers360.com/courses-certifications/articles/django-interview-questions-and-answers
- https://www.interviewbit.com/django-interview-questions/
- https://www.youtube.com/watch?v=OuBUUkQfBYM
- https://www.placementpreparation.io/blog/django-interview-questions-for-freshers/