This Django app allows you to export certain settings to your templates.
Project description
Often it is needed to make some of your Django project’s settings accessible from within templates. This app provides a simple mechanism for doing just that.
Principles:
Explicit is better than implicit: Only explicitly listed settings keys are exported to templates.
Errors should never pass silently: Accessing an undefined or unexported setting key from a template results in an exception.
Tested on Python 2.7+, Django 1.5+.
Installation
$ pip install django-settings-export
Add 'django_settings_export.settings_export' to TEMPLATE_CONTEXT_PROCESSORS in your settings.py:
TEMPLATE_CONTEXT_PROCESSORS = [
# [...]
'django_settings_export.settings_export',
]
Usage
All settings that should be made accessible from templates need to be explicitly listed in settings.SETTINGS_EXPORT:
# settings.py
DEBUG = True
GA_ID = 'UA-00000-0'
SETTINGS_EXPORT = [
'DEBUG',
'GA_ID',
]
Now you can access those exported settings from your templates via settings.<KEY>:
{% if not settings.DEBUG %}
<script>ga('create', '{{ settings.GA_ID }}', 'auto');</script>
{% endif %}
Exceptions:
Listing an undefined setting key in SETTINGS_EXPORT results in an UndefinedSettingError.
Accessing a unexported setting key on the settings object in a template results in an UnexportedSettingError.
See also the bundled demo app.
Development
$ cd demo
# Run demo
$ python manage.py runserver
# Run tests on current Python
$ python manage.py test
# Run tests on all Pythons
$ tox
Licence
BSD. See LICENCE for more details.
Contact
Jakub Roztocil
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
File details
Details for the file django-settings-export-1.0.3.tar.gz
.
File metadata
- Download URL: django-settings-export-1.0.3.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 022e0d3cd27b8efa719d699fa01f9aea1462b81e4587aeb643023dccabd77494 |
|
MD5 | 99dc93a989e8030965be907ae855ae34 |
|
BLAKE2b-256 | c58a6f1f1fa4290b5f7d49ce081c63698e9fb102cb843e92203f52a29eb80991 |