[英]Django context processor not setting request var in template
我有以下觀點:
@login_required
def manage(request):
''' Display the list of posts that belong to the user '''
posts = Post.objects.filter(user=request.user).order_by('created_at')
return render_to_response('posts/manage.html', {'posts':posts}, context_instance=RequestContext(request))
我的模板中的request
變量為空。
我的設置:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
'social_auth.context_processors.social_auth_by_name_backends',
)
我想通過request.user
訪問登錄的用戶。
有什么事嗎 謝謝。
請注意,我正在使用社交身份驗證進行用戶登錄。
將'django.core.context_processors.request'
添加to your TEMPLATE_CONTEXT_PROCESSORS
使用這些上下文處理器,您根本無權訪問request
-但您確實可以直接訪問user
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.