Skip to main content

A helper for organizing Django settings.

Project description

Build Status Jazzband Codecov

django-configurations eases Django project configuration by relying on the composability of Python classes. It extends the notion of Django’s module based settings loading with well established object oriented programming patterns.

Check out the documentation for more complete examples.

Quickstart

Install django-configurations:

pip install django-configurations

Then subclass the included configurations.Configuration class in your project’s settings.py or any other module you’re using to store the settings constants, e.g.:

# mysite/settings.py

from configurations import Configuration

class Dev(Configuration):
    DEBUG = True

Set the DJANGO_CONFIGURATION environment variable to the name of the class you just created, e.g. in bash:

export DJANGO_CONFIGURATION=Dev

and the DJANGO_SETTINGS_MODULE environment variable to the module import path as usual, e.g. in bash:

export DJANGO_SETTINGS_MODULE=mysite.settings

Alternatively supply the --configuration option when using Django management commands along the lines of Django’s default --settings command line option, e.g.:

python manage.py runserver --settings=mysite.settings --configuration=Dev

To enable Django to use your configuration you now have to modify your manage.py or wsgi.py script to use django-configurations’s versions of the appropriate starter functions, e.g. a typical manage.py using django-configurations would look like this:

#!/usr/bin/env python

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
    os.environ.setdefault('DJANGO_CONFIGURATION', 'Dev')

    from configurations.management import execute_from_command_line

    execute_from_command_line(sys.argv)

Notice in line 10 we don’t use the common tool django.core.management.execute_from_command_line but instead configurations.management.execute_from_command_line.

The same applies to your wsgi.py file, e.g.:

import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Dev')

from configurations.wsgi import get_wsgi_application

application = get_wsgi_application()

Here we don’t use the default django.core.wsgi.get_wsgi_application function but instead configurations.wsgi.get_wsgi_application.

That’s it! You can now use your project with manage.py and your favorite WSGI enabled server.

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

django-configurations-2.1.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

django_configurations-2.1-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-configurations-2.1.tar.gz.

File metadata

  • Download URL: django-configurations-2.1.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/36.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

File hashes

Hashes for django-configurations-2.1.tar.gz
Algorithm Hash digest
SHA256 71d9acdff33aa034f0157b0b3d23629fe0cd499bf4d0b6d699b9ca0701d952e8
MD5 da011d87d1936f9eace181eac29b2cfb
BLAKE2b-256 77acee62f66efca11f1ac5d84eae40f29185ce493d8dae4a5de2d5b0ec967159

See more details on using hashes here.

Provenance

File details

Details for the file django_configurations-2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_configurations-2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/36.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

File hashes

Hashes for django_configurations-2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e70433eeed10549d30bf5ca386c962505ff9f492893dd2483c52af536347adce
MD5 bedc7ad71f92fb7e1d039903dc5226a2
BLAKE2b-256 a36acfa9a6d1901217e91d93ee6e54620716a566a413466589035bdbe9d3bb83

See more details on using hashes here.

Provenance

Supported by

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