App-Parameter is a very simple Django app to save application's parameter in the database.
Project description
Django-app-parameter
App-Parameter is a very simple Django app to save application's parameter in the database. Therefor those parameter can be updated by users at running. It can be used to store title of the website, e-mail of the mail expeditor and so on.
Detailed documentation is in the "docs" directory.
Install
pip install django-app-parameter
Quick start
-
Add "django_app_parameter" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... "django_app_parameter", ]
If you want to have your global parameter available in template, activate the provided context processor:
TEMPLATES = [
...
"OPTIONS": {
"context_processors": [
...
"django_app_parameter.context_processors.add_global_parameter_context",
],
},
]
-
Run
python manage.py migrate
to create the django_app_parameter table in models. -
Start the development server and visit http://127.0.0.1:8000/admin/ to create parameters (you'll need the Admin app enabled).
Usage
Use admin interface to add parameters. You can access a parameter in your code use the "slug" field. It's built at first save with: slugify(self.name).upper().replace("-", "_"), examples:
self.name ==> self.slug()
blog title ==> BLOG_TITLE
sender e-mail ==> SENDER_E_MAIL
##weird@Na_me ==> WERIDNA_ME
See Django's slugify function for more informations.
You can read parameter anywhere in your code:
from django_app_parameter.models import Parameter
def send_confirmation_email_view(request):
from = Parameter.objects.str("TEAM_EMAIL")
subject = "Alright!"
...
send_email(...)
You can also access "global" parameters from every templates:
<head>
<title>{{ BLOG_TITLE }}</title>
</head>
Ideas which could come later (or not)
- A migration process to keep a list of your parameters in a file and automatically add them in each environment
- Shortcut to use Parameter.str(slug) (skip 'objects' key word)
- Check correctness of value on save
- Management command to add a new parameter
- modification history
Why Django-App-Parameter
Because I wanted to try to package a Django app and I used this one in most of my projects so it seemed a good idea.
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
Built Distribution
Hashes for django-app-parameter-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56d470e24e1e1db4126925fc8bb79ce3819471aebae8248aed4e6a0b062daa6c |
|
MD5 | fed9c268e91fe64e7714b7550de9f56d |
|
BLAKE2b-256 | 7ba58d52fc618d6a56545fc72c718d768a99f7347b7aab17bc2afb11ca63f1f8 |
Hashes for django_app_parameter-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a6ea82e2b7c1fa219a935938cbc8a81660aed801b18520d2c06325a1e226e8f |
|
MD5 | 0eed416a3f48b45b71ce5a4438fefb3b |
|
BLAKE2b-256 | 07a95c296da5dd4b06aedecbe6f05c8a9811a8ee4a35709ca1561efe0635905f |