Setting up Django Form Wizard

穿精又带淫゛_ 提交于 2020-04-30 14:26:53

问题


I'm attempting to set up a Django Form Wizard, but I'm having trouble getting it to work. I've followed the example, from the Django website, but can't get anything to work. When I go to the URL that should have my multistep form, only the template html thats extended shows up. What am I doing wrong here?

FORMS.PY

    class ScheduleDate(forms.Form):
        date = forms.CharField()

    class ScheduleTime(forms.Form):
        time = forms.CharField()

VIEWS.PY

    FORMS =[('date', ScheduleDate),
         ('time', ScheduleTime)]

    TEMPLATES = [('date', 'main/schedule_date2.html'),
         ('time', 'main/schedule_time.html')]


    class ContactWizard(SessionWizardView):
        def get_template_name(self):
            return TEMPLATES[self.steps.current]

        def done(self, form_list, **kwargs):
            print 'testing'
            return HttpResponseRedirect('main/home.html')

URLS.PY

    urlpatterns = patterns('',
        url(r'^checkout/$', views.ContactWizard.as_view([ScheduleDate,    ScheduleTime]), name='checkout'))

SCHEDULE_DATE2.HTML(From the Django Website)

    {% extends "base.html" %}
    {% load i18n %}

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

    {% block content %}
    <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
    <form action="" method="post">{% csrf_token %}
   <table>
   {{ wizard.management_form }}
   {% if wizard.form.forms %}
        {{ wizard.form.management_form }}
        {% for form in wizard.form.forms %}
            {{ form }}
        {% endfor %}
   {% else %}
        {{ wizard.form }}
  {% endif %}
   </table>
  {% if wizard.steps.prev %}
    <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first    }}">{% trans "first step" %}</button>
    <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
    {% endif %}
   <input type="submit" value="{% trans "submit" %}"/>
  </form>
  {% endblock %}

Thanks!

来源:https://stackoverflow.com/questions/32810324/setting-up-django-form-wizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!