django-configurations
django-configurations copied to clipboard
I wonder, why `post_setup()` wont' change setting values?
I have an exmaple code but apparently, it's not supposed to work as mention here
# `SECRET_KEY not set` error occurs
class Dev(BaseSetting):
SECRET_KEY = 'new_string'
Env = 'Dev
DEBUG = determine_debug()
def determine_debug():
return 'Dev' == settings.Env:
New Trial
# `SECRET_KEY not set` error occurs
class Dev(BaseSetting):
SECRET_KEY = 'new_string'
Env = 'Dev
@classmethod
def post_setup(cls):
super().post_setup()
cls.DEBUG = determine_debug()
Workaround
class Dev(BaseSetting):
SECRET_KEY = 'new_string'
Env = 'Dev
@classmethod
def post_setup(cls):
super().post_setup()
DEBUG = determine_debug()
setattr(setting_module, 'DEBUG', DEBUG)
So I have to call setattr() manually, I think django-configurations is a great tool to manage django configuration so easily but I found a buggy defect out of sudden.
Anyone has a similar expreience?
I have a similar complaint in issue #217.
The documentation on Setup methods says:
Of course that won’t work for
post_setupsince that’s when the settings setup is already done.
Maybe it's the setup() method you need to use. Can you try?
I think I already tried that one before but it seems the docs was updated since I opened this issue.
Perhaps I can try with pre_setup(), however, that time I'm pretty sure that I have tried all kinds of methods that I can try.
Actually, now I changed the way I use django-configurations so that I wouldn't need to override setting like that anymore.
Thanks for your replay!!