Skip to main content

Define constants in your settings, and make them available in your templates.

Project description

django-tagconstants

Define constants in your settings file, that are then made available in your templates.

Installation

From the command line:

pip install django-tagconstants

Add tagconstants to your installed apps:

INSTALLED_APPS = (
    ...
    'tagconstants',
    ...
)

Create a TAG_CONSTANTS dictionary in your settings.py file:

TAG_CONSTANTS = {}

Usage

For security purposes, tagconstants is designed so that you create a whitelist of variables to make available in your templates. For more information see the Design and Security section.

To use a constant in your templates, first add the constant to your TAG_CONSTANTS setting:

TAG_CONSTANTS = {
    'CONSTANT': 'SOME STRING',
}

Then in your templates, you can recall these constants with the {% constant ... %} template tag:

{% load tagconstants %}

{% constant "CONSTANT" %}
    {# renders to 'SOME STRING' #}

{% constant "CONSTANT" as "variable_name" %}
    {# loads the template variable variable_name="SOME STRING" #}
    {# into the template context #}

Contributing

Pull, fork, do whatever you’d like with the code.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tagconstants-0.1.zip (9.4 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