我的setting.py里有这个
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
)每当我尝试访问模板(例如{{ request.user.get_profile.custom_username }})中的请求时,都得不到任何结果。我认为请求没有添加到模板中,因为如果我强制请求进入上下文(在视图中),我就可以访问它:
ctx = {}
#ctx['request'] = request
return render_to_response('index.html', ctx)有什么帮助吗?谢谢
发布于 2012-02-13 19:09:47
请改用渲染快捷方式,这样更容易记住:
return render(request, 'index.html', ctx)发布于 2012-02-13 19:05:37
在django 1.3中,需要将RequestContext传递给模板。您可以使用render自动包含此内容,或者如果您需要使用render_to_response,请尝试:
return render_to_response('index.html',
ctx,
context_instance=RequestContext(request))https://stackoverflow.com/questions/9259298
复制相似问题