Django Administrable configuration variables
The django django_admin_conf_vars app allows you to have configuration variables for your project with the Django admin
# Installation
Install from pip
$ pip install django-admin-conf-vars
Add django_admin_conf_vars to your INSTALLED_APPS
Migrate to create the databases:
$ python manage.py migrate
Don’t worry about the warnings, they are shown only the first time. (It’s becouse the next configuration is not ready yet)
Create a python module named like you want. eg: ‘my_var_settings_file.py’ and put it into your project. eg: my/path/package/my_var_settings_file.py. Define your variables in that file:
# -*- coding:utf-8 -*- from django_admin_conf_vars.global_vars import config config.set("MY_TIME_VAR", default=60) config.set("MY_OTHER_VAR", default="/some/path", editable=False) ...
Be sure to have migrated and have the database created at this point. See How to use
Add to your settings.py the path of your new module:
VARS_MODULE_PATH = 'my_package.my_var_settings_file'
The variable VARS_MODULE_PATH must to have the name of your new file (point 4). Be sure to put it into an existing python package.
Ready! Now you have configuration variables with django admininistration. Just use it in you views, models or any python module. See How to use
## Upgrating from old version
If You have installed previous versions, you need to migrate again, but first you must to comment the line in your settings.py # VARS_MODULE_PATH = ‘my_package.my_var_settings_file’.
Comment the VARS_MODULE_PATH in your settings.py
Upgrade via pip $ pip install –upgrade django_admin_conf_vars.
Migrate $ python manage.py migrate
Uncomment the VARS_MODULE_PATH
Run the server
## Dependences
Django >= 1.7
# How it works
django_admin_conf_vars use the Singleton design pattern to guarantee that only exists one instance of your configuration variables and that when you import the config variable always you have the global variables in a single object with your variables in its attributes. See global_vars.py.
django_admin_conf_vars doesn’t use the database every time you import it, it only connect to the database in two cases:
Every time you restart your server.
Every you modified a single var in the admin.
django_admin_conf_vars allows you to define global vars in your code, and too allows to edit them with the django admin. If you modify a variable with the admin, this always will keep the value of the database, and never will rewrite with the value inside the code. If you want to use the value inside the code, you can edit it in the admin and copy that value :)
# Differences between normal settings variables and django_admin_conf_vars
## Normal usage:
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. (Ͼ˳Ͽ)..!!!
## django_admin_conf_vars usage:
You writte your variables and use them like normal usage.
Your vars in my_var_settings_file.py:
# -*- coding:utf-8 -*-
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
...
Simple! Now you can edit those variables with the django admin
Metadata
Release files for django-admin-conf-vars 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_admin_conf_vars-0.4.1.tar.gz | 6.6 kB | Without provenance | Details for django_admin_conf_vars-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_admin_conf_vars-0.4.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for django_admin_conf_vars-0.4.1-py2.py3-none-any.whl |
Total release size: 15.9 kB
Release files / django_admin_conf_vars-0.4.1.tar.gz
| Download URL | django_admin_conf_vars-0.4.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ede6001955b468634ef1ef96bdc9e74e88c5f5936930d6d9f7f1e766d0777372
|
|
BLAKE2b-256 checksum How to use checksums |
59441bc67bc287575dcb756f6be9ddfcefb71f3c630a1cc8011dcf94b0276066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_admin_conf_vars-0.4.1-py2.py3-none-any.whl
| Download URL | django_admin_conf_vars-0.4.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
bae7827e6334fbd017759d20517ad43d2c0af87d886b4e01dbd123cefe24a186
|
|
BLAKE2b-256 checksum How to use checksums |
c60f27d0e695695c2bd0b38f5157d7acca5d082503e1ba71bc6ce75aa9ce8507
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-admin-conf-vars 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.