Django提交表单之前先进行确认 [英] Django Confirm a form before submitting it

查看:38
本文介绍了Django提交表单之前先进行确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,可以在form.cleaned_data中检索数据.我希望将此数据呈现到另一个页面上,以供提交者在将其输入数据库之前进行检查.现在,我可以只使用render(request,"xyz.html","datax":form.cleaned_data}将其呈现给用户,但我仍然停留在如何从此页面以POST形式重新提交此数据的过程中.我应该如何在下一页中存储这些数据,以便可以通过确认"按钮将其重新发送给我.

I've got a form which I retrieve data for in form.cleaned_data. I wish to render this data to another page for the submitter to review before it is entered in the DB. Now, I can just use render(request,"xyz.html","datax":form.cleaned_data} to render it to the user, but I am stuck at how to re-submit this data as POST from this page. How should I store this data in the next page so that it can be resent to me with my "confirm" button.

请不要在Django中建议表单预览.我不想使用它,而是自己写.

Please do not suggest form preview in django. I do not wish to use that, but write my own.

推荐答案

不发送form.cleaned_data,而仅发送表单

Don't send form.cleaned_data but just the form

每个示例:

# In view1
form = Form(request.POST)
if form.is_valid():
    return render(request, 'view2.html', form)

# In view2
form = Form(request.POST)
if form.is_valid():
    form.save()

这篇关于Django提交表单之前先进行确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆