gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:53 24 4
gpt4 key购买 nike

编辑: 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))

我想将 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.

关于python - 如何让 django 表单向导 extra_context 显示在模板上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com