Looking in django.conf I noticed that settings are implemented like this:
class LazySettings(LazyObject):
...
What is the rationale behind making settings objects lazy?
Looking in django.conf I noticed that settings are implemented like this:
class LazySettings(LazyObject):
...
What is the rationale behind making settings objects lazy?
Its a proxy object that abstracts the actual settings files, and makes it light weight until you actually access the settings you want. Once you start accessing the attributes, it will then load on demand. The idea is to reduce overhead in loading settings until you need them.
Check out this section of the Django coding style. The reason is explained in there (quoted below).
In addition to performance, third-party modules can modify settings when they are imported. Accessing settings should be delayed to ensure this configuration happens first.
I think that the purpose is to simplify settings from a developers point of view. So each project can have its own settings.py file without having the need to define all other Django settings as well. The
LazySettings
wrapper kind of combines everything from Django global_settings.py and your local settings. It lets the developer decide what settings he wants to overwrite, which he want to keep the defaults or which he wants to add.The
LazySettings
class is maybe a wrong name for this, because I think it is not really lazy. Once you do something likefrom django.conf import settings
the whole settings object is in your scope.