A simple Django app to have configuration variables for your project with the Django admin.
Project description
The django django_admin_conf_vars app allows you to have configuration variables for your project with the Django admin
# Installation
Install from pypi
$ pip install django-admin-conf-vars
Add django_admin_conf_vars to your INSTALLED_APPS
Migrate python manage.py migrate to create the databases
Create a file ‘my_settings_conf.py’ next to your settings.py and define your variables:
from django_admin_conf_vars.global_vars import config config.set("MY_TIME_VAR", default=60) config.set("MY_OTHER_VAR", default="/some/path")
Add to your settings.py file:
GLOBAL_VARS_PATH = 'my_package.my_settings_conf'
The variable GLOBAL_VARS_PATH must to have the name of your new file (point 4). Be sure to locale in a python package.
Ready! Now you have configuration variables with django admininistration.
# Differences between normal settings variables and django_admin_conf_vars
## Normal:
Your vars in the settings.py:
MY_TIME_VAR = 60 MY_OTHER_VAR = "/some/path"
Using your vars in a view.py:
from django.conf import settings def my_view(request): ... a = settings.MY_TIME_VAR b = settings.MY_OTHER_VAR ...
Conclusion: You have static variables written in your settings.py
but… what happen if you want to edit some of those variables in production? You need to edit the settings and reload your server. (Ͼ˳Ͽ)..!!!
## With django_admin_conf_vars:
You writte your variables and use them like normal usage.
Your vars in my_var_settings_file.py:
from django_admin_conf_vars.global_vars import config config.set("MY_TIME_VAR", default=60) config.set("MY_OTHER_VAR", default="/some/path")
And using your vars in a view.py:
from django_admin_conf_vars.global_vars import config def my_view(request): ... a = config.MY_TIME_VAR b = config.MY_OTHER_VAR
Now you can edit those variables with the django admin
# How it works
django_admin_conf_vars use the Singleton design pattern to guaranteeing that only exist one instance of your configuration variables and your view calls doesn’t use the database every time, but rather a single object with your variables as attributes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-admin-conf-vars-0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13e93c403b3dee1a4e4e0e13dbb785f30a91720945996ee4a68517e4b60583a3 |
|
MD5 | 24aca58ec514b9400e5e60c273d81eb7 |
|
BLAKE2b-256 | 4fa089ea56d1674102900d9555bce237d154727bef3d5920e7bda52c0d0dbb8c |