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)
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With