相关疑难解决方法(0)

从基于类的通用视图中获取request.session

有没有办法request.session从基于类的视图中获取?

例如,我有

from django.views.generic.edit import FormView

class CreateProfileView(FormView):
    def form_valid(self, form):
        # --> would like to save form contents to session here

        return redirect(self.get_success_url())
Run Code Online (Sandbox Code Playgroud)

我唯一能想到的就是as_view通过添加覆盖

def as_view(self, request, *args, **kwargs):
    self.session = request.session
    super(CreateProfileView, self).as_view(request, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

上课.但这看起来很难看.还有另外一种方法吗?

django django-views

33
推荐指数
1
解决办法
2万
查看次数

标签 统计

django ×1

django-views ×1