在我的Django webapp中,我有一个用户向Form1.html提交数据。数据传递到Form2.html,在那里他们提交更多数据。提交Form2后,他们将被带到Done.html。
Form1>> Form2>>完成
问题是我需要完成视图中From2 和中Form1的数据。从Form1获取数据到Form2视图没有问题,只需从request.POST['value']
中获取值。在Form2视图中,如何将Form1数据传递给Done视图?我认为我可以像下面一样修改Form2中的POST对象并传递请求对象:
def form2(request):
form1string = request.POST['inputbox1']
request.POST = request.POST.copy() # make the POST QueryDict mutable
request.POST.setdefault('data1', form1string)
t = loader.get_template('done.html')
c = RequestContext( request, { # pass on old request so new POST data is passed on
'blah': some_var,
})
c.update(csrf(request)) # add the csrf_token to the Context dictionary
return HttpResponse(t.render(c))
我对使用django.sessions
犹豫不决,因为不是每个人都启用了Cookie。
提前感谢您的帮助!
答案 0 :(得分:1)
我会在这里开始阅读:http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
关于会议犹豫不决:
它在散列HTML字段中维护状态