问题
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