Django Confirm a form before submitting it

十年热恋 提交于 2021-02-08 08:52:43

问题


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.

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


回答1:


Don't send form.cleaned_data but just the form

Per example :

# 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()



回答2:


It's probably better to submit it straight to the database in the first step, but add a "reviewed" booleanfield which is only set to true after the second step.



来源:https://stackoverflow.com/questions/25041417/django-confirm-a-form-before-submitting-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!