Reputation: 523
I have a ListView in my views.py but in this class, I want to check session if the user exit in the session which has been kept in during login
class part_list_view(ListView):
model = part_list
context_object_name = 'part_list'
template_name = 'part_list.html'
def get_context_data(self, **kwargs):
context = super(part_list_view, self).get_context_data(**kwargs)
context['my_list'] = populate_nav_bar()
return context
Upvotes: 1
Views: 603
Reputation: 9931
use self.request
anywhere in the class based view. In your case self.request.session
def get_context_data(self, **kwargs):
session = self.request.session
# now use session however you want
context = super(part_list_view, self).get_context_data(**kwargs)
context['my_list'] = populate_nav_bar()
return context
Upvotes: 2