Giter VIP home page Giter VIP logo

django-compose-settings's Introduction

Django composable settings loader

We are under CI!!

Aims to compose your settings from python modules and python scripts in /etc.

In your my_app/settings/__init__.py call the loader:

from django_compose_settings import modules_loader

locals().update(modules_loader(prefix='my_app', default='base,etc,post'))

In my_app/settings/base.py define default values as usual, ex:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# ...

In my_app/settings/etc.py call the etc loader:

from django_compose_settings import etc_loader

locals().update(etc_loader(prefix='my_app'))

You can validate settings in my_app/settings/post.py as follow:

import __settings__

assert hasattr(__settings__, 'BASE_DIR'), 'BASE_DIR required'

Etc settings

Here is a sample tree of your /etc/my_app:

/etc/my_app/
├── settings.d
│   ├── 00_prod1.py
│   └── 99_local.py
└── settings.py

Each .py file is a regular composable settings file as post.py above.

MY_APP_SETTINGS

You can override your settings with a specific SETTINGS environment variable for your app as follow:

$ MY_APP_SETTINGS=base,post python

>>> import logging
>>> logging.basicConfig(
...     level=logging.INFO,
...     format='%(asctime)s %(levelname)-8s %(name)s  %(message)s'
... )

>>> import os
>>> import sys
>>> sys.path.append(os.path.join(os.path.abspath('tests'), 'fixtures'))

>>> from my_app import settings

2015-11-23 10:59:09,964 INFO     django_compose_settings  Loaded my_app.settings.base
2015-11-23 10:59:09,964 INFO     django_compose_settings  Loaded my_app.settings.post

django-compose-settings's People

Contributors

bersace avatar toopy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-compose-settings's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.