[Django]-Get request.session from a class-based generic view

71👍

You have access to self.request from anywhere within the class (and therefore self.request.session)

https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/#dynamic-filtering

The key part to making this work is that when class-based views are called, various useful things are stored on self; as well as the request (self.request) this includes the positional (self.args) and name-based (self.kwargs) arguments captured according to the URLconf.

Leave a comment