Skip to main content

Per-app default settings for Django

Project description

DjAppSettings: Per-App Settings for Django

  • I hate pasting blobs into my settings.py every time I enable an app.

  • This is a Python module which provides a sane way for reusable Django apps to configure themselves.

  • 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.

  • 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.

  • App settings are prevented from clobbering built-in settings. They can only add settings.

  • Project settings (in DJANGO_SETTINGS_MODULE) override app settings.

  • Using per-app prefixes is a good idea, but not mandatory.

But, but

  • I’m aware of Jared Forsyth’s django-appsettings, and I think it’s lovely but wrong. Project settings should not be editable in the Django admin.

  • 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.

  • 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.

Usage

Where you would usually do something like:

from django.conf import settings
getattr(settings, "MY_SETTING", "DEFAULT")

Create a settings.py file in your app, containing:

MY_SETTING = "DEFAULT"

and do something like:

from djappsettings import settings
settings.MY_SETTING

If you’d like to support this module where available, but fall back to the usual method if not, just try it:

try: from djappsettings import settings
except: from django.conf import settings
settings.MY_SETTING

Installation

Via Pip:

$ pip install djappsettings

Via GitHub:

$ git clone git://github.com/adammck/djappsettings.git
$ python djangoappsettings/setup.py install

Bugs?

This was created to scratch an itch for the RapidSMS project. I hope it will be useful to you, 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.)

Patches and pull requests are very welcome. Please file bugs on GitHub.

License

djappsettings is free software, available under the BSD license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djappsettings-0.2.0.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file djappsettings-0.2.0.tar.gz.

File metadata

  • Download URL: djappsettings-0.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for djappsettings-0.2.0.tar.gz
Algorithm Hash digest
SHA256 70c0a29ebc7616e7ba28babf1ae3ed7f9daa14d807123bb9b9e25b1a7db791bc
MD5 8173fe2e962bc39f787fa76691e4a737
BLAKE2b-256 329cb1b0dc550f40521d24c92ec4b1839956fbbe246932f81cd2651975276c52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page