Providing custom settings with default values
Hello there,
until now I (and many others) used to define default custom settings
in <myapp>/settings.py in this way:
from django.conf import settings
default = lambda k, v: getattr(settings, k, v)
PREFIX_KEY = default('PREFIX_KEY', 'value')
...
and in other modules I used django-settings along my own settings like
this:
from django.conf import settings
from <myapp> import settings as <myapp>_settings
That's easy-enough solution, but has several problems:
1. ./manage.py diffsettings doesn't work with this approach
2. <myapp>/settings.py is a little bit messy
3. You have to REPEAT one line of code (with lambda) and thus violate
DRY principle. Well, this is not problem at all, I'm just trying to
get your attention ;)
I've found two years old article by Thomas Sutton's about different
approach http://passingcuriosity.com/2010/default-settings-for-django-applications/
and after reading through his repository I decided to create fork,
update his work and publish it. It's nothing special, just one
function, the reason why I packed it and posted to pypi (http://
pypi.python.org/pypi/django-application-settings/0.1a) is that now I
can easilly install it into virtualenv and share it within different
projects/apps.
The usage is simple:
1. Add these two lines somewhere to __init__.py in your application
directory:
from application_settings import provide_default_settings
provide_default_settings(__name__)
2. Create settings.py in your application directory and write your own
settings as you would write in project/settings.py
I would appreciate any feedback or suggestions about different
approaches. Thanks!
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home