Django在一个页面上形成向导多个表单集

时间:2014-08-06 15:42:15

标签: python django forms django-formwizard

我正在尝试使用表单向导在Django中创建一个表单,其中在向导的同一步骤中有多个(重复)表单集。

我拥有的是:

# forms.py
class FormStep1A(forms.Form):
    answerA = forms.CharField(max_length=100)
    remarkA = forms.CharField(widget=forms.Textarea)

class FormStep1B(forms.Form):
    answerB = forms.CharField(max_length=100)
    remarkB = forms.CharField(widget=forms.Textarea)

class FormStep1(forms.Form):
    partA = formset_factory(FormStep1A)
    partB = formset_factory(FormStep1B)

# urls.py
STEPS = (
    ('1', FormStep1),
    # ...
)
# FormWizard is a subclass of NamedUrlSessionWizardView
wizard = FormWizard.as_view(STEPS, url_name='form_new_step')
urlpatterns = patterns(
    '',
    url(r'^new/(?P<step>.+)/$', wizard,
        name='form_new_step'),
    url(r'^new/$', wizard, name='form_new'),
)

我的模板与documentation中的模板相同。但是,我的表单呈现为空,根本没有字段。

我知道那里有类似的问题或食谱:

但我无法让这个工作。非常感谢任何帮助,谢谢!

更新:我的模板如下所示:

{% extends 'base.html' %}

{% load i18n %}

{% block head %}
  {{ wizard.form.media }}
{% endblock %}

{% block content %}

  <div class="row">
    <div class="large-12 columns">
      <h3>{% trans "Questionnaire" %}</h3>
      <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
        <form action="" method="post">
          {% csrf_token %}
          {{ wizard.management_form }}
          {% if wizard.form.forms %}
            {{ wizard.form.management_form }}
            {% for form in wizard.form.forms %}
              {{ form }}
            {% endfor %}
          {% else %}
            {{ wizard.form }}
          {% endif %}
          {% if wizard.steps.prev %}
            <button class="button tiny" name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "First step" %}</button>
            <button class="button tiny" name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "Prev step" %}</button>
          {% endif %}
          <input class="button tiny" type="submit" value="{% trans "Submit" %}"/>
        </form>
    </div>
  </div>

{% endblock %}

0 个答案:

没有答案