Django 在基于类的视图中访问request.user
我想在使用此视图加载模板时显示当前用户。有办法吗Django 在基于类的视图中访问request.user,django,Django,我想在使用此视图加载模板时显示当前用户。有办法吗 class IndexView(generic.ListView): template_name = 'app/template.html' context_object_name = 'drinks' def get_queryset(self): return Drinks.objects.all() 如果使用基于类的通用视图或渲染快捷方式,则可以简单地使用{{user},只要上下文处理器在模板设置中包含'djan
class IndexView(generic.ListView):
template_name = 'app/template.html'
context_object_name = 'drinks'
def get_queryset(self):
return Drinks.objects.all()
如果使用基于类的通用视图或渲染快捷方式,则可以简单地使用{{user},只要上下文处理器在模板设置中包含'django.contrib.auth.context{u processors.auth'。在template.html中,可以使用{request.user}例如{request.user.first{name}。如果需要登录,可以使用{{request.user.is_authenticated}