Django request in template

I turned on 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", ) 

However, I do not need to query the variable available in the templates. I have to manually pass this. Using django 1.0.2 Throughout the network, this only looks like a request handler.

I also use RequestContext like:

  return render_to_response( 'profile.html', { 'persons':Person.objects.all(), 'person':Person.objects.get(id=id), 'request':request, }, context_instance=RequestContext(request) ) 

Bad luck

ohh darn new name for this TEMPLATE_CONTEXT_PROCESSORS

+19
django request processor
Mar 31 '09 at 19:09
source share
5 answers

settings.py:

 TEMPLATE_CONTEXT_PROCESSORS = ( # ... 'django.core.context_processors.request', # ... ) 
+39
Apr 2 2018-10-14T00:
source share

TEMPLATE_CONTEXT_PROCESSORS instead of TEMPLATE_PROCESSORS

+10
Mar 31 '09 at 19:24
source share

Please note that with Django 1.8 this has changed to the "TEMPLATES" parameter, and the query processor is NOT enabled in the default configuration.

 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 return the query processor to fix the problem:

 'django.core.context_processors.request', 

For more information, see Django Upgrading Docs .

+4
Feb 04 '16 at 20:11
source share

Are you sure you do not have the request variable available for the template? What happens when you delete a row

 'request':request, 

which is different from when this line is present. If your template loads the same way, the problem is with your template.

0
Mar 31 '09 at 21:06
source share

MIDDLEWARE_CLASSES = (... 'Yourfolder.yourfile.yourclass', ... YourClass:

class AddRequestToTemplate: process_templaet_response (self, request, response): response.context_data ['request'] = request

0
Nov 17 '13 at 14:13
source share



All Articles