【问题标题】:Django form wizard - passing request to the view?Django 表单向导 - 将请求传递给视图?
【发布时间】: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() 方法?

【问题讨论】:

    标签: django django-forms django-formwizard


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多