Often times you’ll find that you need to use a constant that’s defined in your Django settings within a template. Unfortunately Django only provides access to a handful of settings by default. Anything beyond that small set, including custom constants that you have defined, are not accessible.
The easiest way to deal with this problem is to make use of a context processor. First, create a new file called context_processors.py within your application:
In this example I am making two constants available within my templates – GOOGLE_ANALYTICS and GOOGLE_API_KEY.
Next, add this new context processor to your settings:
Now you can make use of the constant from within your template: