How to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST

I read it

"DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST If TEMPLATE_CONTEXT_PROCESSORS contains this processor, each RequestContext will contain a variable request that is the current HttpRequest. Note that this processor is not enabled by default; you will have to activate it." From this page

http://docs.djangoproject.com/en/dev/ref/templates/api/

But there seems to be no information on how to activate this processor.

Here is my original question

Access request in django template custom tags

After I completed the answer

I still got errors

TemplateSyntaxError at / Caught an exception while rendering: 'request' Original Traceback (most recent call last): File "C:\Python25\lib\site-packages\django\template\debug.py", line 71, in render_node result = node.render(context) File "C:\Python25\lib\site-packages\django\template__init__.py", line 936, in render dict = func(*args) File "c:\...\myapp_extras.py", line 7, in login request = context['request'] File "C:\Python25\lib\site-packages\django\template\context.py", line 44, in getitem raise KeyError(key) KeyError: 'request' 

code causing problem

request = context ['request'] in

 from django import template register = template.Library() @register.inclusion_tag('userinfo.html',takes_context = True) def userinfo(context): request = context['request'] address = request.session['address'] return {'address':address} 
+4
source share
2 answers

I answered this here: How to transfer data to any template from any view in Django?

Also see comments on my answer ... you may need this information as well.

+2
source

in settings.py

 from django.conf import global_settings TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ( 'django.core.context_processors.request', ) 
+2
source

Source: https://habr.com/ru/post/1300326/


All Articles