加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 11:21:50 所属栏目:Python 来源:网络整理
导读:编辑: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(se
编辑: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,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))

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

我如何在模板上获得它?

我试过模板:

{{extra_context}}
{{form.extra_context}}
{{form.extra_context.ptype}}

等等..

解决方法

看看 docs我会说 get_context_data就是你所追求的:

Returns the template context for a step. You can overwrite this method to add more data for all or some steps. This method returns a dictionary containing the rendered form step.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读