1

我有以下看法:

@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.

有什么问题?谢谢。

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

4

2 回答 2

8

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

于 2012-08-22T17:37:39.970 回答
6

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

于 2012-08-22T18:14:59.823 回答