Skip to main content

This Django app allows you to export certain settings to your templates.

Project description

PyPi Build Status of the master branch Coverage

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.


  • 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+.


$ pip install django-settings-export

Add 'django_settings_export.settings_export' to template context processor list in your

Django 1.8 and newer:

        # …
        'OPTIONS': {
            'context_processors': [
                # …

Django older than 1.8:

    # [...]


All settings that should be made accessible from templates need to be explicitly listed in settings.SETTINGS_EXPORT:


DEBUG = True
GA_ID = 'UA-00000-0'


Now you can access those exported settings from your templates via settings.<KEY>:

<!-- template.html -->

{% if not settings.DEBUG %}
    <script>ga('create', '{{ settings.GA_ID }}', 'auto');</script>
{% endif %}

The settings variable is an instance of dict subclass, so you use all the methods dict provides. For example, you can iterate over the keys and values using , settings.keys, settings.values, settings.items, etc:

{% for key, value in settings.items %}
    {{ key }}: {{ value }}
{% endfor %}

Changing the settings variable name

If you wish to change the name of the context variable to something besides settings, add SETTINGS_EXPORT_VARIABLE_NAME = 'custom_name' to your This is useful when some other plugin is already adding settings to your template contexts.

FOO = 'bar'
<!-- template.html -->

{{ my_config.FOO }}


These custom exceptions can be thrown:

  • 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.

All subclass from django_settings_export.SettingsExportError.

Demo & Tests

See the source code of the bundled demo app.


$ cd tests

# Run demo
$ python runserver

# Run tests on current Python
$ python test

# Run tests on all Pythons
$ tox

Change Log



BSD. See LICENCE for more details.


Jakub Roztocil

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.2.1.tar.gz (5.0 kB view hashes)

Uploaded Source

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