Django Confidence is a Django app to make configuration files automatically.
This app is developed to help developers create their own layout to configuration files quick and simple with built-in dictionaries or by using configuration presets (that make it even more easier).
-
Run
pip install django-confidence
-
Add the
confidence
package to yourINSTALLED_APPS
setting like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'confidence',
]
- In your settings.py import
Configuration
class fromconfidence
package like this:
from confidence import Configuration
- Create a dictionary of config fieldsets like this:
markup = {
'section': {
'option': 'value'
},
'project': {
'project_name': 'Awesome Project',
}
}
- In your settings.py create a variable called
PROJECT_CONF
and fill it with aConfiguration
instance:
PROJECT_CONF = Configuration(filepath, markup)
Optional. You can use library of preset configuration files by importing from conf.presets. Example:
from confidence import Configuration
from confidence.presets import ProjectPreset, OptionsPreset
PROJECT_CONF = Configuration.compile_from_presets(filepath, [
ProjectPreset(name='Awesome Project', version='1.0', site_url='http://awesome!'),
OptionsPreset(debug=True, allowed_hosts=['127.0.0.1']),
])
-
Run
python manage.py makeconfig
. Configuration file will be created. -
Edit your configuration file as you want to.
-
Use it in your
settings.py
by using get-like methods::
PROJECT_NAME = PROJECT_CONF.get('project', 'project_name')
DEBUG = PROJECT_CONF.get_bool('options', 'debug')
ALLOWED_HOSTS = PROJECT_CONF.get_csv('options', 'allowed_hosts')
- Enjoy!
Configuration presets are intended to simplify the process of setting up configuration files.
Presets are using default and most common options for provided services.
At this moment there are different presets for some of common database management systems, cache and mailing modules.
Usage: from confidence.presets import [PRESET_NAME]
-
MySQL:
confidence.presets.MySQLPreset
-
PostgreSQL:
confidence.presets.PostgreSQLPreset
- Redis:
confidence.presets.RedisPresets
- MailDev:
confidence.presets.MailDevPreset
-
makeconfig [--force]: creates a configuration file at specified in
PROJECT_CONF
(Configuration
instance) declared atsettings.py
. Optional: use [--force] to overwrite file if it exists. -
repairconfig: repairs configuration file if any configuration sections or options are missing.