Skip to main content

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.

It tries to make settings management easier by:

  • Requiring you to be explicit about what settings should be exported to templates.

  • Failing loudly if an undefined or unexported setting is accessed.

Installation

$ pip install django-settings-export

Add 'django_settings_export.export_settings' to TEMPLATE_CONTEXT_PROCESSORS in your settings.py:

TEMPLATE_CONTEXT_PROCESSORS = [
    # [...]
    'django_settings_export.export_settings',
]

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.

Development

Run tests:

$ cd demo
$ python manage.py test

Licence

BSD. See LICENCE for more details.

Contact

Jakub Roztočil

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

django-settings-export-1.0.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-settings-export-1.0.1.tar.gz.

File metadata

File hashes

Hashes for django-settings-export-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b809a232e3beaae2ecad194f2c493f23bdc06c0394e6f22d2a114dcda2adc83c
MD5 dfe45239598ee79f832d6fe7f58c1ea0
BLAKE2b-256 47d33ca5b7b383b41ab27707cb7a66d6c69b59eeb895bf4b39a8962c5b373ca3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page