Reputation: 578
I've enabled the Django request processor
TEMPLATE_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)
Still I don't have to request variable available in templates. I've to manually pass it. Using Django 1.0.2. Everywhere on web it seems it's only about enabled request processor.
Also I am using RequestContext
as:
return render_to_response(
'profile.html',
{
'persons':Person.objects.all(),
'person':Person.objects.get(id=id),
'request':request,
},
context_instance=RequestContext(request)
)
No luck.
ohh darn the new name for that is TEMPLATE_CONTEXT_PROCESSORS
Upvotes: 22
Views: 44090
Reputation: 831
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.
Upvotes: 8
Reputation: 1
MIDDLEWARE_CLASSES=( ... 'yourfolder.yourfile.yourclass', ... yourclass:
class AddRequestToTemplate: process_templaet_response(self, request, response): response.context_data['request']=request
Upvotes: 0
Reputation: 2706
settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
'django.core.context_processors.request',
# ...
)
Upvotes: 46
Reputation: 12803
Are you sure you don't have the request
variable available to the template? What happens when you remove the line
'request':request,
that's different from when that line is present. If your template loads the same either way, the problem is with your template.
Upvotes: 1