Django |如何将表单值传递到重定向页面 [英] Django | How to pass form values to a redirected page
本文介绍了Django |如何将表单值传递到重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的职能:
def check_form(request):
if request.method == 'POST':
form = UsersForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
try:
newUser = form.save()
return HttpResponseRedirect('/testproject/summery/)
except Exception, ex:
# sys.stderr.write('Value error: %s\n' % str(ex)
return HttpResponse("Error %s" % str(ex))
else:
return render_to_response('index.html', {'form': form}, context_instance=RequestContext(request))
else:
form = CiviguardUsersForm()
return render_to_response('index.html',context_instance=RequestContext(request))
我想将每个字段传递给夏季调用页面,并在用户提交表单时显示所有字段,以便用户在确认注册之前可以查看它.
I want to pass each and every field in to a page call summery and display all the fields when user submits the form, so then users can view it before confirming the registration.
谢谢..
推荐答案
您可以使用所有表单字段构建字典,并使用"render_to_response":
You could build a dictionnary, with all your form fields, and use "render_to_response" :
newUser = form.save()
data = {}
for field in dir(newUser):
if isinstance(getattr(newUser, field), Field):
data[field] = getattr(newUser, field)
return render_to_response('summary.html', data, context_instance=RequestContext(request))
并使用模板中的变量?
这篇关于Django |如何将表单值传递到重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文