7
我想在基於類的視圖中獲取當前登錄的用戶。我可以通過從請求對象中提取用戶來做到這一點,但我如何獲得該對象?在基於類的視圖中獲取請求對象
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