Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added README.

  • Loading branch information...
commit 8d07561a3cfd9db6a2e7a41732c527f4d712a15c 1 parent b011cd3
Adam Mckaig authored

Showing 1 changed file with 76 additions and 0 deletions. Show diff stats Hide diff stats

  1. +76 0 README.md
76 README.md
Source Rendered
... ... @@ -0,0 +1,76 @@
  1 +Django App Settings
  2 +===================
  3 +
  4 +* I hate pasting blobs into my settings.py every time I enable an app.
  5 +
  6 +* This is a Python module which provides a sane way for reusable Django apps to configure themselves.
  7 +
  8 +* It's a drop-in replacement for the `django.conf.settings` class. You can fetch all of your project, app, and global default settings via a single `settings` object.
  9 +
  10 +* It doesn't touch your project's settings module, and existing Django apps are free to ignore it. Your app can even fall back to the usual method if this module isn't available.
  11 +
  12 +* App settings are prevented from clobbering [built-in settings](1). They can only *add* settings.
  13 +
  14 +* Project settings (in DJANGO_SETTINGS_MODULE) override app settings.
  15 +
  16 +* Using per-app prefixes is a good idea, but not mandatory.
  17 +
  18 +
  19 +But, but
  20 +--------
  21 +
  22 +* I'm aware of [Jared Forsyth](2)'s [django-appsettings](3), and I think it's lovely but wrong. Project settings should not be editable in the Django admin.
  23 +
  24 +* I'm also aware that this feature has been rejected numerous times on the Django trac. But pasting a bunch of junk into my settings.py each time I add an app is a pain in the ass.
  25 +
  26 +* I saw [this snippet](4). It's insufficient.
  27 +
  28 +* Checking for a setting (via settings.hasattr), and falling back to a hard-coded default value is a terrible solution, because your defaults are duplicated and buried. They should be easily discoverable.
  29 +
  30 +
  31 +Usage
  32 +-----
  33 +
  34 +Where you would usually do something like:
  35 +
  36 + from django.conf import settings
  37 + getattr(settings, "MY_SETTING", "DEFAULT")
  38 +
  39 +Create a `settings.py` file in your app, containing:
  40 +
  41 + MY_SETTING = "DEFAULT"
  42 +
  43 +and do something like:
  44 +
  45 + from djangoappsettings import settings
  46 + settings.MY_SETTING
  47 +
  48 +If you'd like to support this module where available, but fall back to the usual method if not, just `try` it:
  49 +
  50 + try: from djangoappsettings import settings
  51 + except: from django.conf import settings
  52 + settings.MY_SETTING
  53 +
  54 +
  55 +Installation
  56 +------------
  57 +
  58 + $ git clone git://github.com/adammck/django-app-settings.git
  59 + $ cd django-app-settings
  60 + $ python setup.py install
  61 +
  62 +
  63 +Bugs!
  64 +-----
  65 +
  66 +This was created to scratch an itch for the [RapidSMS](5) project. I hope it will be useful to others, but it doesn't have any docs or tests yet, and hasn't been field tested. There are almost certainly bugs. Use it at your own risk. (But do use it, because it's *way* better.)
  67 +
  68 +Patches and pull requests are very welcome.
  69 +Please file bugs on [GitHub](6).
  70 +
  71 +[1] http://code.djangoproject.com/browser/django/trunk/django/conf/global_settings.py
  72 +[2] http://github.com/jabapyth
  73 +[3] http://github.com/jabapyth/django-appsettings
  74 +[4] http://www.djangosnippets.org/snippets/573/
  75 +[5] http://rapidsms.org
  76 +[6] http://github.com/adammck/django-app-settings/issues

0 comments on commit 8d07561

Please sign in to comment.
Something went wrong with that request. Please try again.