Settings namespaced by app_label

37 views
Skip to first unread message

Michael

unread,
Jul 28, 2022, 8:48:56 AM7/28/22
to Django developers (Contributions to Django itself)
Models and URLSs (kind of) are namespaced by the app_label.
I am making a Django CSS app to open source, and it requires settings. For now I am just going to copy DRF and use a dict to avoid collisions.

What if in settings.py we could do something like this (where one has an app with an app_label of 'foo'):
FOO_SETTINGS = {
   'POGO_STICKS': 5,
   'MORE_SETTINGS': [1,2,3],
}

or (what I think is better) use class based approach:
# Here DjangoAppSettings is just a subclass of maybe a dataclass, to use in isintance tests to find the settings (like how TestCase's are found).
FooSettings(DjangoAppSettings):
   POGO_STICKS = 5
   MORE_SETTINGS = [1,2,3]

Then in the app that consumes the settings, maybe do something like this (or something different):
from django.conf import settings
apps.get_app_config('foo').settings

And it would return FooSettings
I have not given it much thought, but its just concept I am proposing, not the exact implementation.
Reply all
Reply to author
Forward
0 new messages