How access constants in from templates in Django?

  1. Make a file in your app directory. Let’s say I want to have the ADMIN_PREFIX_VALUE value in every context:
from django.conf import settings # import the settings file

def admin_media(request):
    # return the value you want as a dictionnary. you may add multiple values in there.
    return {'ADMIN_MEDIA_URL': settings.ADMIN_MEDIA_PREFIX}

2. Add your context processor to your file:

    # whatever comes before
    'OPTIONS': {
        'context_processors': [
            # whatever comes before

3. Use RequestContext in your view to add your context processors in your template. The render shortcut does this automatically:

from django.shortcuts import render

def my_view(request):
    return render(request, "index.html")

4. Finally, in your template:

<a> href="{{ ADMIN_MEDIA_URL }}">path to admin media </a>