4

I've written a view to toggle the setting.DEBUG variable. hoping to enable and disable DEBUG feature of Django for my website.

from myApp import settings
def toggleDEBUGView(request):
    if request.user.is_superuser:
        settings.DEBUG = not(settings.DEBUG)

I've set DEBUG=Falsein settings.py. So even if the DEBUG is set to true via my custom view. I still get Server Error (500)

swapnil jariwala
  • 1,064
  • 2
  • 12
  • 19
  • See this seems duplcate http://stackoverflow.com/questions/6528723/changing-django-settings-at-runtime – MaNKuR Jul 10 '14 at 16:08

1 Answers1

3

Lets quote couple of things here from the Django documentations https://docs.djangoproject.com/en/dev/topics/settings/#using-settings-in-python-code

1) django.conf.settings isn’t a module – it’s an object: That too a tuple. and as we know tuples position value cant be altered as it is an immutable object.

2) Settings is being included at the earliest: Thats means settings objects is being created when you start server.

In my opinion the settings content/variables can be changed at runtime only when it will reload the settings that I think is a non-trivial problem.

This will help as well Changing Django settings at runtime

Please let me know if you achieved this by any short of medium. It will be a great help for me as well :)

Community
  • 1
  • 1
MaNKuR
  • 2,578
  • 1
  • 19
  • 31