Django上下文处理器未在模板中设置请求var

Ale*_*and 1 django django-templates django-socialauth

我有以下观点:

@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))
Run Code Online (Sandbox Code Playgroud)

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',
)
Run Code Online (Sandbox Code Playgroud)

我想通过登录用户访问request.user.

可能有什么不对?谢谢.

请注意,我使用社交身份验证进行用户登录.

Bra*_*don 8

'django.core.context_processors.request' to your TEMPLATE_CONTEXT_PROCESSORS


Dan*_*man 6

使用这些上下文处理器,您根本无法访问request- 但您可以user直接访问.