Задать вопрос

Тел: +7 965 3737 888





Automagically import settings from installed applications

<p>Use this snippet at the end of your main settings.py file to automagically import the settings defined in each app of INSTALLED_APPS that begins with APPS_BASE_NAME.</p>
<p>Set APPS_BASE_NAME to the base name of your Django project (e.g. the parent directory) and put settings.py files in every app directory (next to the models.py file) you want to have local settings in.</p>
# works in the Django shell
&gt;&gt;&gt; from django.conf import settings
&gt;&gt;&gt; settings.TEST_SETTING_FROM_APP
"this is great for reusable apps"

<p>Please keep in mind that the imported settings will overwrite the already given and preceding settings, e.g. when you use the same setting name in different applications.</p>
<p>Props to <a href="">bartTC</a> for the idea.</p>

Вопрос полезен? Да0/Нет0

Ответы (1):

Ответ полезен? Да0/Нет0

Isn't it a better approach to set the default values in the app and overwrite them in the main settings.py when necessary? For example:


from django.conf import settings
TEST_SETTING = getattr(settings, "TEST_SETTING", "default value")