1

I have deployed my Django project on Ubuntu and I forgot to set the Debug to False till the very end, now I have pulled the last commit to the server with the debug set to False. So now when I try to access a non existing url, for example, it should display my custom 404.html template.

Instead it displays the Debug mode 404 error instead telling me that Debug = True even if it's not, I checked the settings.py file on the server and Debug is set to False.

I tried restarting nginx and supervisor with service nginx restart and supervisorctl restart my_app_name but when I enter a non existing url it still says that Debug is set to True.

Why does it still say that Debug is set to True?

UPDATE: following the answer received I went over the possible issues proposed and found none of them. Furthermore, when I run the exact same project on the local machine it works just fine with Debug = False.

If I run on the server the SAME EXACT project, with the same exact code and files/file structure (they are "synchronized" with github) it shows that the Debug is set to True, so there must be something related to the configuration on the server.

SECOND UPDATE: after adding a new domain in the ALLOWED_HOSTS list of the settings.py file, it is disregarding that as well. So it's not just a problem of the DEBUG variable, it is disregarding every change made to the settings.py file. Could it be Cloudfare Caching? If yes, what's a way to prevent this?

Tommy D
  • 440
  • 1
  • 3
  • 13
  • 1
    Any chance this is heroku? –  Aug 28 '20 at 12:24
  • No, it is not. I am using a Ubuntu server with an own IP address. – Tommy D Aug 28 '20 at 12:26
  • 1
    You're going to have to debug it then. Run the `/path/to/bin/python manage.py shell` with the python interpreter that supervisor is using and type `import settings` following by `settings.DEBUG`. If that shows True, then it is True and you are overriding it somewhere. If it shows False, then nginx is maybe not talking to the right app? Cloudflare Cache? Really hard to guess... –  Aug 28 '20 at 12:29
  • What WSGI server are you using? I often have to restart gunicorn (my WSGI of choice) after changes. Is the `DEBUG` setting's value determined by an environment variable? – gsundberg Aug 28 '20 at 12:33
  • I am using gunicorn with supervisor, and I tried several times to restart supervisor with `supervisorctl restart app_name`. Is this not the correct way to restart gunicorn? – Tommy D Aug 29 '20 at 11:23

1 Answers1

1

Because it is. Common causes:

  • DEBUG=False and 30 lines later DEBUG=True
  • DJANGO_SETTINGS_FILE is pointing to a different file then you've changed the DEBUG setting in
  • on the bottom of the settings file another file, commonly named local_settings.py is imported and that has DEBUG=True
  • on the bottom of the settings file is some logic that imports environment variables overwriting previous definitions
  • DEBUG = 'False' # this is True
  • Thanks for proposing your solutions, but I encountered none of the suggested issues. Furthermore If I run the exact same Project with the exact same code on the local machine, it works just fine and the Debug is set to False, as per settings.py – Tommy D Aug 28 '20 at 12:24
  • 1
    could you run `grep DEBUG . -R` in django folder ? – mansuetus Aug 28 '20 at 13:00