Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get request object in class-based View

Tags:

I want to get the current logged in user in a class-based view. I can do that by extracting the user from the request object, but how can I obtain that object?

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