1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import copy
from django.conf import settings as django_settings
default = {
'YOURAPPS_SETTING_1': True,
'YOURAPPS_ENTRIES_PER_PAGE': 25,
}
# Make copy of the original settings, to avoid altering the
# project wide settings module.
settings = copy.copy(django_settings)
# Populate default_settings in settings if they aren't set.
for key, value in default.items():
if not hasattr(settings, key):
setattr(settings, key, value)
|
More like this
- Automagically import settings from installed applications by jezdez 5 years, 3 months ago
- Overwrite some views in settings.py by guettli 4 years, 1 month ago
- localsettings by elpaso66 3 years, 2 months ago
- Jinja2 Django integration by mathwizard 4 years, 8 months ago
- db_dump.py - for dumpping and loading data from database by limodou 6 years, 2 months ago
Comments
What about:
It doesn't seemed annoying to me...
#
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.
#
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.#