![](/img/trans.png)
[英]Inserting initial data into a SessionWizardView form field either from a URL pattern or post data?
[英]Correct <form action=“ ” URL for a SessionWizardView
我在让Django SessionWizardView将数据提交到我的数据库时遇到了一些麻烦 ,并且我试图找出问题所在。
我从表单文档中注意到
表单及其元素还必须指定两件事:
- 其中:应将与用户输入相对应的数据返回到的URL
- 方式:数据应通过的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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.