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 details)

Uploaded Source

File details

Details for the file django-tagconstants-0.1.zip.

File metadata

File hashes

Hashes for django-tagconstants-0.1.zip
Algorithm Hash digest
SHA256 0e2ae4a2e00183cce86f3d95f8396e6e5239aefe280687e07dd7238e2a24f93e
MD5 7693f2692e9993849586288ad9eed7a0
BLAKE2b-256 1af9ecf04276443794a0b9f175e353d2ab3ac8eb50458bded5f33a3367511435

See more details on using hashes here.

Supported by

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