Get request.session from a class-based generic view

后端 未结 1 499
故里飘歌
故里飘歌 2020-12-05 06:32

Is there a way to get request.session from inside a class-based view?

For instance, I have

from django.views.generic.edit import FormV         


        
相关标签:
1条回答
  • 2020-12-05 07:10

    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.

    0 讨论(0)
提交回复
热议问题