Django SessionWizardView不执行done方法

时间:2014-09-30 12:55:36

标签: python django forms wizard

我无法使SessionWizardView正常工作。当我提交最后一步时,向导会跳回到第一步并且不执行done方法。

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 %}

谢谢!

2 个答案:

答案 0 :(得分:0)

尝试将用户直接发送到html页面。在这种情况下,将page_i_want_to_send_user.html更改为您希望用户在完成表单后发送到的页面的名称

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],            
            }) 

在这种情况下,page_i_want_to_send_user.html页面存储在模板目录

答案 1 :(得分:0)

您可能遇到字段验证错误。尝试添加行

{{ wizard.form.non_field_errors }}
{{ wizard.form.errors }}

后,

{{ wizard.management_form }}
在你的html模板文件中。这应该显示任何阻止done方法执行的验证错误。