What are functional differences between DEBUG = True and False in Django?

前端 未结 3 852
小蘑菇
小蘑菇 2021-01-05 18:12

What precisely are the functional differences between toggling the DEBUG setting in a settings.py file of a Django app?

I first assumed

相关标签:
3条回答
  • 2021-01-05 18:26

    One of the main advantages of DEBUG=True is of detailed error pages. Django provides a detailed stacktrace of what went wrong. Which is immensely helpful in debugging. Basically, in DEBUG mode, django remembers every SQL query it executes(Which again makes it totally not suitable for production).

    Additionally, if DEBUG=True, host validation is disabled. In other words, if DEBUG=False, ALLOWED_HOSTS needs to be set.

    0 讨论(0)
  • 2021-01-05 18:31
    1. The DEBUG=True, if there is error, page will show details of error.

    2. if DEBUG=False, the ALLOWED_HOSTS of settings.py will work, you should take carefully to set it.

    3. the media and static will not provide access for DEBUG=False, you have to provide them with the help of webserver, like Nginx or Apache.

    0 讨论(0)
  • 2021-01-05 18:32

    As of Django 1.6.2 it has been identified before that import errors are not necessarily caught in DEBUG=True but certainly are in DEBUG=False

    Simple example: Try importing your app's settings.py (import yourapp.settings) into one of your views and then try referencing a non-existent variable: settings.var_that_does_not_exist. This will only be an issue (causing status 500 errors) for when DEBUG=False for any views that reference that non-existent variable.

    0 讨论(0)
提交回复
热议问题