Django 表单向导 - 将请求传递给视图?

Posted

技术标签:

【中文标题】Django 表单向导 - 将请求传递给视图?【英文标题】:Django form wizard - passing request to the view? 【发布时间】:2012-05-17 12:38:24 【问题描述】:

有没有办法在表单向导的 done() 方法中访问 request 变量?

class AddWizard(SessionWizardView):
    def done(self, form_list, **kwargs):
        if form_list[0].cleaned_data['ad_type'] == '1':
            ad_type = 'basic'
        else:
            ad_type = 'other'
        return render_to_response('business/done.html', 
            'form_data': ad_type,
            ,
            context_instance = RequestContext(request)
        )

我想访问请求中的用户对象,但我不确定如何将请求传递给 done() 方法?

【问题讨论】:

【参考方案1】:

是的。 SessionWizardView 扩展了基本通用 View,因此请求在 self.request 中可用。

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

【讨论】:

以上是关于Django 表单向导 - 将请求传递给视图?的主要内容,如果未能解决你的问题,请参考以下文章