【问题标题】:Django: Form set using SesionWizardViewDjango:使用 SessionWizardView 设置表单
【发布时间】:2012-08-28 22:32:01
【问题描述】:

我对 Django 中的表单集有疑问。我在网上找不到答案。

https://docs.djangoproject.com/en/1.4/ref/contrib/formtools/form-wizard/

我正在尝试使用此文档制作示例,但我不知道如何更改默认模板。

我知道我应该在ContactWizard 类中使用get_template_names(),但我不知道这个方法应该是什么样子。

感谢您的帮助!

【问题讨论】:

    标签: django forms get wizard formset


    【解决方案1】:

    get_template_names() 应根据您的逻辑(例如步骤、表单等)返回模板名称。

    例如示例模板根据步骤或步骤编号等的形式返回不同的模板。

     def get_template_names(self):
        if issubclass(self.get_form(str(self.steps.current)).__class__, BaseModelFormSet):
            return 'wz_formset_template.html' #depending upon form type
        else if self.steps.current == 2 :  #depending upon step
            return 'wz_step_2_template.html' 
        return 'wz_form_template.html'   #default template
    

    【讨论】:

    • 好的,我明白了,但是我应该在哪里写这个方法?在 ContactWizard(SessionWizardView) 类的 forms.py 中?我是 django 表单的新手...
    • 是的,这是您的向导视图类的方法(您在其中定义了done 方法。)
    • 好吧,我不明白,但是当我打开这个 url 时,我的 urls.py urlpatterns = patterns('', (r'^contact/$', ContactWizard.as_view([ContactForm1, ContactForm2])), ) (/contact/) 我仍然有默认视图...我做错了什么?
    • @Silwest 你能用相关视图、模板代码更新你的问题吗?
    • 我的代码看起来很糟糕;/你能给我看一些views.py的例子吗?
    猜你喜欢
    • 2011-10-16
    • 2015-03-04
    • 1970-01-01
    • 2014-05-02
    • 2023-04-10
    • 2010-10-12
    • 2012-06-14
    • 2019-11-09
    • 2014-11-25
    相关资源
    最近更新 更多