【问题标题】:Django SessionWizardView doesn't execute done methodDjango SessionWizardView 不执行完成方法
【发布时间】:2014-11-25 02:48:11
【问题描述】:

我无法让我的 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 %}

谢谢!

【问题讨论】:

  • 你怎么知道done()方法没有被调用? wizard_done 网址是什么?

标签: python django forms wizard


【解决方案1】:

尝试将用户直接发送到 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 页面存储在模板目录中

【讨论】:

  • 感谢您的回答。我尝试了您的解决方案,但它不起作用。表单在最后一步提交后不断跳回第一步。 (对不起我的英语)
【解决方案2】:

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

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

行后,

{{ wizard.management_form }}

在您的 html 模板文件中。这应该会显示阻止 done 方法执行的任何验证错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-27
    • 2019-07-07
    • 1970-01-01
    • 2015-03-04
    • 2019-10-31
    • 2018-06-01
    • 2011-09-07
    相关资源
    最近更新 更多