django-compressor/django-appconf

Question: Is it possible to override settings from django?

stefanfoulis opened this issue · 3 comments

In my app I'm trying to override a setting that has a default in django (LOGIN_URL) based on a special setting in my app.

I tried setting LOGIN_URL on an AppConf with Meta.prefix = '', but that obviously just picks up the default setting from django (LOGIN_URL='/accounts/login') instead of using the default value specified on my configuration.

If you import the Django settings object from your app's conf module, then yes, you could easily override it in the AppConf configure_* methods, e.g.:

class MyAppConf(AppConf):
    SPAM = True
    EGGS = False

    def configure_eggs(self, value):
        # value comes from your project settings
        if value == True:
            # self._meta.holder is the django.conf.settings object
            self._meta.holder.LOGIN_URL = 'http://something.completely.different/'
        return value

Does that solve your problem?

yes, that looks like exactly what I need. Thanks!

w00t!