Why is django's settings object a LazyObject?

后端 未结 3 1254
孤独总比滥情好
孤独总比滥情好 2021-01-04 12:57

Looking in django.conf I noticed that settings are implemented like this:

class LazySettings(LazyObject):     
...

What is the rationale be

3条回答
  •  情深已故
    2021-01-04 13:16

    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 like from django.conf import settings the whole settings object is in your scope.

提交回复
热议问题