Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically changing DEBUG mode of django via a view

Tags:

python

django

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)

like image 672
swapnil jariwala Avatar asked Oct 24 '25 17:10

swapnil jariwala


1 Answers

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 :)

like image 120
MaNKuR Avatar answered Oct 26 '25 07:10

MaNKuR