1
不設置請求變種我有以下觀點:Django的上下文處理器在模板
@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
訪問登錄的用戶。
出了什麼問題?謝謝。
請注意,我正在使用社交身份驗證用戶登錄。
偉大的答案丹尼爾。 @alexBrand,除非你還需要'request'中的其他東西,Daniel的答案可以爲你節省額外的上下文處理器。 – Brandon