django request in template django request in template django django

django request in template


settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (  # ...  'django.core.context_processors.request',  # ...)


TEMPLATE_CONTEXT_PROCESSORSinstead of TEMPLATE_PROCESSORS


Be advised that as of Django 1.8, this has changed to a "TEMPLATES" setting, and in the default configuration, the request processor is NOT included.

TEMPLATES = [{    'BACKEND': 'django.template.backends.django.DjangoTemplates',    'DIRS': [        # insert your TEMPLATE_DIRS here    ],    'APP_DIRS': True,    'OPTIONS': {        'context_processors': [            # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this            # list if you haven't customized them:            'django.contrib.auth.context_processors.auth',            'django.template.context_processors.debug',            'django.template.context_processors.i18n',            'django.template.context_processors.media',            'django.template.context_processors.static',            'django.template.context_processors.tz',            'django.contrib.messages.context_processors.messages',        ],    },},]

Just add the request processor back in to fix the issue:

'django.core.context_processors.request',

For more info, see the Django Upgrading Docs.