Home > front end >  Django still working fine even when DEBUG=False in settings.py
Django still working fine even when DEBUG=False in settings.py

Time:03-16

In settings.py, DEBUG set to True. But when we move it to the production we should be setting DEBUG=False.

So in my local environment itself, I have changed to DEBUG=False. But still my application is working fine even with this settings. Usually when we changed DEBUG to false we should be getting some issues like 500 or 404 error something like that , but in my case its not like that. I have referred this """ https://stackoverflow.com/questions/38617046/django-debug-false-still-runs-in-debug-mode/47266619""" but it did not help much for me.

Please let me know if i misunderstood or missed something.

Below is the small snippet of code i have in settings.py

import os
BASE_DIR = 
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
DEBUG = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
'MyApp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',    
]
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
 ]

Please let me know if i need to provide anymore details.

CodePudding user response:

The purpose of DEBUG is to control what happens when the application encounters an error.

If that happens and DEBUG is true, then the error page will contain debugging information that is useful to developers.

But you would not want this information to be shown to real users, so DEBUG should be false when deployed to production.

Setting DEBUG to false does not cause errors, as you seem to think.

CodePudding user response:

I have found that it is giving 500 error to me after i change to DEBUG=FALSE(missed this before). Now please let me know what can be the reason for this error by seeing the above code

  • Related