【发布时间】:2015-08-02 00:16:11
【问题描述】:
I have been having some trouble 获取 Django SessionWizardView 以将数据提交到我的数据库,我正在尝试隔离问题。
除了元素之外,表单还必须指定两件事:
- where:对应用户输入的数据应返回到的 URL
- how:数据返回的 HTTP 方法
和
发送回 Django 网站的表单数据由视图处理, 与发表表格的观点大致相同。这使我们能够 重复使用一些相同的逻辑。
目前我使用的是<form action="/surveyone/" method="post">,我认为这是正确的。
问题是我的视图名为class SurveyWizardOne(SessionWizardView):,但如果我尝试在form action 中使用它,我会在单击调查第一页上的下一步时立即收到错误消息。
问题:根据以下内容,action="/surveyone/" 是否正确?
谢谢
urls.py
url(r'^surveyone/$', SurveyWizardOne.as_view([
SurveyFormIT1,
SurveyFormIT2,
Start,
SurveyFormA,
SurveyFormB,
SurveyFormC,
SurveyFormD,
SurveyFormE,
SurveyFormSpike1,
SurveyFormF1,
SurveyFormF2,
SurveyFormF3,
SurveyFormDV1,
SurveyFormF4,
SurveyFormF5,
SurveyFormF6,
SurveyFormSpike2,
SurveyFormDV2,
SurveyFormF7,
SurveyFormF8,
SurveyFormF9,
SurveyFormDV3,
SurveyFormDV4,
SurveyFormDV5,
SurveyFormG,
SurveyFormH,
SurveyFormI
])),
views.py
class SurveyWizardOne(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(SurveyWizardOne, self).get_context_data(form, **kwargs)
step = int(self.steps.current)
....
....
return context
def done(self, form_list, **kwargs):
return render(self.request, 'Return_to_AMT.html', {
'form_data': [form.cleaned_data for form in form_list],
})
wizard_form.html
{% extends "base.html" %}
{% load i18n %}
{% block head %}
{{ wizard.form.media }}
{% endblock %}
{% block content %}
<div class="main_content">
<p>Page: {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
<form action="/surveyone/" 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>
【问题讨论】:
标签: django django-forms django-templates django-views