我想在基于类的视图中获取当前登录的用户。我可以通过从请求对象中提取用户来做到这一点,但是我怎样才能获得该对象呢?
class HomeView(TemplateView):
template_name='home.html'
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
context['username'] = request.user.username
return context