Skip to main content

Simple class-based settings for Django

Project description


Minimalist approach to class-based settings for Django

Quick Start

In your

from cbs import BaseSettings, env

# For env settings with a DJANGO_ prefix
denv = env['DJANGO_']

class Settings(BaseSettings):

    DEBUG = denv.bool(True)  # Controlled by DJANGO_DEBUG env var

    DEFAULT_DATABASE = denv.dburl('sqlite://db.sqlite')

    def DATABASES(self):
        return {
            'default': self.DEFAULT_DATABASE,

class ProdSettings(Settings):
    DEBUG = False

    def STATIC_ROOT(self):
        raise ValueError("Must set STATIC_ROOT!")

__getattr__, __dir__ = BaseSettings.use()

Switch between Settings and ProdSettings using the DJANGO_MODE env var:

# Run default Settings
$ ./ test

# Run ProdSettings
$ DJANGO_MODE=prod ./ test

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-classy-settings-3.0.1.tar.gz (5.5 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page