返回Django表单内容错误 [英] Return Django form contents on error
本文介绍了返回Django表单内容错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部
我有一个模板页面说x.html
I have a template page say x.html
我有3个文本字段名称(varchar2),age(int),school(varchar2)。
i have 3 text fields name(varchar2) ,age(int),school(varchar2) in it.
如果用户以x.html的形式输入值(例如value name =a ,age =2,school =a)并提交。我需要将相同的值返回到x.html表示错误。
If the users enters values in the form in x.html(say values name="a" ,age="2" ,school="a") and submit it.I need to return the same values back to x.html indicating an error.
我的问题是如何将相同的值返回给x.html。
My question is how to return the same values to x.html.
谢谢.....
推荐答案
从 docs :
在视图中处理表单的标准模式如下所示:
The standard pattern for processing a form in a view looks like this:
def contact(request):
if request.method == 'POST': # If the form has been submitted...
form = ContactForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = ContactForm() # An unbound form
return render_to_response('contact.html', {
'form': form,
})
这篇关于返回Django表单内容错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文