Skip to main content

A helper class for handling configuration defaults of packaged apps gracefully.

Project description

Build Status PyPI version

A helper class for handling configuration defaults of packaged Django apps gracefully.

Overview

Say you have an app called myapp with a few defaults, which you want to refer to in the app’s code without repeating yourself all the time. appconf provides a simple class to implement those defaults. Simply add something like the following code somewhere in your app files:

from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = (
        "two",
    )

The settings are initialized with the capitalized app label of where the setting is located at. E.g. if your models.py with the AppConf class is in the myapp package, the prefix of the settings will be MYAPP.

You can override the default prefix by specifying a prefix attribute of an inner Meta class:

from appconf import AppConf

class AcmeAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = (
        "two",
    )

    class Meta:
        prefix = 'acme'

The MyAppConf class will automatically look at Django’s global settings to determine if you’ve overridden it. For example, adding this to your site’s settings.py would override SETTING_1 of the above MyAppConf:

ACME_SETTING_1 = "uno"

Since django-appconf completes Django’s global settings with its default values (like “one” above), the standard python manage.py diffsettings will show these defaults automatically.

In case you want to use a different settings object instead of the default 'django.conf.settings', set the holder attribute of the inner Meta class to a dotted import path:

from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = (
        "two",
    )

    class Meta:
        prefix = 'acme'
        holder = 'acme.conf.settings'

If you ship an AppConf class with your reusable Django app, it’s recommended to put it in a conf.py file of your app package and import django.conf.settings in it, too:

from django.conf import settings
from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = (
        "two",
    )

In the other files of your app you can easily make sure the settings are correctly loaded if you import Django’s settings object from that module, e.g. in your app’s views.py:

from django.http import HttpResponse
from myapp.conf import settings

def index(request):
    text = 'Setting 1 is: %s' % settings.MYAPP_SETTING_1
    return HttpResponse(text)

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_appconf-1.2.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_appconf-1.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file django_appconf-1.2.0.tar.gz.

File metadata

  • Download URL: django_appconf-1.2.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for django_appconf-1.2.0.tar.gz
Algorithm Hash digest
SHA256 15a88d60dd942d6059f467412fe4581db632ef03018a3c183fb415d6fc9e5cec
MD5 c51f12f52eec62c73e80ecaf5ba29d6a
BLAKE2b-256 d1a2e58bec8d7941b914af52a67c35b5709eceed2caa2848f28437f1666ed668

See more details on using hashes here.

File details

Details for the file django_appconf-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_appconf-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for django_appconf-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b81bce5ef0ceb9d84df48dfb623a32235d941c78cc5e45dbb6947f154ea277f4
MD5 d37ee7785d53daa52605af24e4920c4d
BLAKE2b-256 e8e64c34d94dfb74bbcbc489606e61f1924933de30d22c593dd1f429f35fbd7f

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