Default Settings for Django Applications
This repository contains a proof of concept Django application that ships default values for its own settings. This is good for a number of reasons:
The application's settings are included in the output of
Application code can just use
getattr(settings, 'MY_SETTING', 'The default value').
Application settings are defined in a single place, with sane default values and, hopefully, with comments. Don't Repeat Yourself!
The actual code is rather simple: it just uses the opportunity afforded it
when the application module is loaded to inject its own default settings into
django.conf.global_settings module (Django's built-in default
settings, and the source for things like the
command) and the
django.conf.settings object (being careful to check to see
if it already contains a value).
To see more, take a look at:
foo/settings.py- the default settings for the app.
foo/__init__.py- the code to inject these defaults.
foo/context_processors.py- the code that uses these new settings.
This is slightly less than a perfect solution (being able to patch
django.conf.settings is initialised),
but the hypothetical perfection is simply not possible: the settings must be
loaded before they can be used to import the
A more complete solution to this problem might allow applications to modify various settings instead of adding only new settings: things like enabling its middleware or request context processors by default, for example. Alas, it's late and I'm tired, so I'll leave that to someone else; this trick is good enough for my purposes as it stands.