0

What is the standard, preferred way to make settings available to templates in Django 1.8? Currently, I define a custom context processor in my project and then reference it in my TEMPLATES OPTIONS setting. I've looked through the docs but didn't find this issue mentioned. This previous Stackoverflow question says to do what I'm doing but it's over two years old and I'm wondering if there's a newer preferred method. If I've learned one thing from recently upgrading Django, it's to do things the way the framework wants you to do them. You'll have fewer problems this way.

Thanks.

# utils/context_processors.py
from profile.models import UserProxy
from conf.settings import base as base_settings

def global_constants(request):
    """Constants that are available to all templates."""
    return {
        'site_name': base_settings.SITE_NAME,
        'media_url': base_settings.MEDIA_URL
    }

# myproject/settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',             # default
                'django.template.context_processors.request',           # default
                'django.contrib.auth.context_processors.auth',          # default
                'django.contrib.messages.context_processors.messages',  # default
                'utils.context_processors.global_constants',            # project
            ],
        },
    },
]
Community
  • 1
  • 1
Jim
  • 13,430
  • 26
  • 104
  • 155
  • It's not clear what you're asking here. Yes, the way to make values available in a template is to use a context processor. Why wouldn't it be? – Daniel Roseman Sep 23 '15 at 20:27
  • I was just asking if there was any newer ways of doing this. I had to change a lot of things during the 1.8 upgrade and I'd like to get this right. I guess I did. – Jim Sep 23 '15 at 21:24

0 Answers0