如何在模板上显示django表单向导extra_context?

tee*_*ane 3 python forms django django-formwizard

编辑: FWIW,我正在运行django 1.3

我有...

class CreateProductWizard(FormWizard):
    def get_template(self, step):
        if step == 1:
            return 'product/form_wizard/editor.html'
        else:
            return 'product/form_wizard/wizard_%s.html' % step
    def process_step(self, request, form, step):
        if step == 1:
            self.extra_context = {'ptype': form.cleaned_data}
            return
        else:
            return
    def done(self, request, form_list):
        # now that it's all together, store it.
        return render_to_response('product/form_wizard/done.html',
            {'form_data': [form.cleaned_data for form in form_list]},
            context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

我想将self.extra_context放到模板中.

我如何在模板上获得它?

我试过模板:

{{extra_context}}
{{form.extra_context}}
{{form.extra_context.ptype}}
Run Code Online (Sandbox Code Playgroud)

等等..

ari*_*rie 5

看看文档,我会说get_context_data你就是这样:

返回步骤的模板上下文.您可以覆盖此方法以为所有步骤或某些步骤添加更多数据.此方法返回包含呈现的表单步骤的字典.

  • 大约五年后,我再次谷歌这个问题,并发现我的堆栈溢出问题.这次你的回答是我的解决方案.哈! (2认同)