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

Тел: +7 965 3737 888

435

Просмотров

3

Ответов

Default settings for a app

<p>Save this as conf.py in the app's directory. Now you can do from myapp.conf import settings.</p>
<p>You can access from the imported object every item of your settings.py including the default settings of myapp. Though you don't have to define every setting in settings.py you use in your app. Now you can ommit annoying try...except statements to define defaults directly in the code.</p>

Вопрос полезен? Да0/Нет0
file_3551.py(460.0б)
None

Ответы (3):

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

It is right what carljm says. First I always used one settings.py file in every app for its default values with: getattr(django_settings, 'MYDEFAULT_SETTING', app_settings.MYDEFAULT_SETTING) But that was to verbose for me. Though now i just import ONE settings module and have all settings in one place including default values.

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

This snippet does have the advantage that all your default settings are defined in one place, instead of scattered throughout the application code. Makes it easier for someone picking up the app to see what settings they can define for it.

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

What about:

getattr(settings, YOURAPPS_ENTRIES_PER_PAGE, 25)

It doesn't seemed annoying to me...