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

Тел: +7 965 3737 888

433

Просмотров

1

Ответов

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
file_3483.py(768.0б)
None

Ответы (1):

Ответarchatas:11.02.2008
Ответ полезен? Да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:

blog/model.py

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