我有一个如下的初始表格
表格.py
class LoginForm(forms.Form):
activity_no = forms.CharField()
username = forms.CharField()
视图.py
def test(request):
if request.method == 'POST' :
form = LoginForm(request.POST)
if form.is_valid() :
act_no = form.cleaned_data['activity_no']
username = form.cleaned_data['username']
form_data = {}
form_data['activity_no'] = act_no
form_data['username'] = username
return render_to_response("test1.html", { 'form_data' : form_data}, context_instance=RequestContext(request))
else:
form = LoginForm()
return render_to_response("test.html", {'form': form }, context_instance=RequestContext(request))
测试.html
{% extends "admin/base.html" %}
{% block content %}
<form action="/todo/test/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
test1.html
{% extends "admin/base.html" %}
{% block content %}
<form action="/todo/login/" method="post">{% csrf_token %}
{% for name, data in form_data.items %}
<input type="hidden" name={{name}} value={{data}}>
{% endfor %}
<input type="submit" value="Yes"/>
</form>
{% endblock %}
我填写此表单,显示文件的少量内容并将上述表单数据传递给表单向导但是当我通过模板中的 post 方法将数据传递给表单向导时,我收到“ManagementForm Data missing”错误,但如果数据通过 GET 方法传递,我没有收到任何错误,但按照定义,数据显示在 GET 方法的 url 中(在我的情况下,它包含我不想透露的用户名)
我的表单向导
class LoginWizard(SessionWizardView):
def __name__(self):
"""When using decorators, Django tries to get the name of the
function and since we're a class, we'll fail. So add this method to
compensate."""
return 'LoginWizard'
template_name = "wizard_form.html"
def done(self, form_list, **kwargs) :
form_data = process_form_data(form_list)
我的疑问是我将如何处理表单向导中的发布数据。如果我遗漏任何内容或需要任何其他信息,请告诉我。