2014-09-30 51 views
3

我无法让我的SessionWizardView工作。当我提交最后一步时,向导跳回第一步,不执行done方法。Django SessionWizardView不执行完成方法

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

谢谢!

+0

你怎么知道'done()'方法没有被调用?什么是'wizard_done'网址? – Rohan 2014-09-30 12:58:17

回答

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页面存储模板目录内

+0

Thaks为答案。我尝试你的解决方案,但它不起作用。在最后一步提交后,表单会一直跳回到第一步。 (对不起我的英语不好) – Francisco 2014-09-30 20:36:05

0

你可能有一个字段验证错误。试着增加线路,

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

行后,

{{ wizard.management_form }} 

在HTML模板文件。这应该显示任何验证错误,阻止执行完成方法。

相关问题