问题
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