问题
I can't make my SessionWizardView work. When I submit the last step, the wizard jumps back to the first step and does not execute the done method.
views.py
class CvWizardView(CookieWizardView):
form_list = [InfoPersonalForm, PresentacionForm]
template_name = 'postulantes/cv_wizard.html'
def done(self, form_list, **kwargs):
return HttpResponseRedirect(reverse('wizard_done'))
urls.py
url(r'^wizard/$', CvWizardView.as_view() , name="wizard"),
html
{% extends "base.html" %}
{% load i18n %}
{% block extra_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!
回答1:
Try sending the user directly to a html page. In this case change page_i_want_to_send_user.html
to the name of the page you want the user to be sent to after they complete the form
class CvWizardView(CookieWizardView):
form_list = [InfoPersonalForm, PresentacionForm]
template_name = 'postulantes/cv_wizard.html'
def done(self, form_list, **kwargs):
return render_to_response('page_i_want_to_send_user.html', {
'form_data': [form.cleaned_data for form in form_list],
})
In this case the page_i_want_to_send_user.html
page is stored inside the templates directory
回答2:
You may have a field validation error. Try adding the lines,
{{ wizard.form.non_field_errors }}
{{ wizard.form.errors }}
after the line,
{{ wizard.management_form }}
in your html template file. That should display any validation errors which are preventing the done method from executing.
来源:https://stackoverflow.com/questions/26121428/django-sessionwizardview-doesnt-execute-done-method