gpt4 book ai didi

django - 如何激活 DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST

转载 作者:行者123 更新时间:2023-12-04 20:25:04 26 4
gpt4 key购买 nike

我读了这个

DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST

If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every RequestContext will contain a variable request, which is the current HttpRequest. Note that this processor is not enabled by default; you'll have to activate it.



来自 this page

但似乎没有信息如何激活这个处理器。

这是我原来的问题

Access request in django custom template tags

在我按照答案之后

我仍然有错误
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'

导致问题的代码是

request = context['request']
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}

最佳答案

我在这里回答:How can I pass data to any template from any view in Django?

另请参阅对我的回答的评论……您可能也需要这些信息。

关于django - 如何激活 DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2202328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com