Django Session 表格(暂时保存表格)

Django Session Form (save form temporarily)

我已经创建了一个审核表单页面。所有用户都可以填写表单,但只有登录用户才能提交表单。如果用户没有登录,他们将被重定向到登录页面。他们登录后,将被重定向到个人资料页面。

所以流程会是这样的: 用户填写表单 > 点击提交 > 重定向到登录页面 > 用户登录并重定向到个人资料页面(同时,他们填写的表单会自动保存)

我希望他们填写的表格在他们登录后自动保存。怎么做到的?

我的想法是创建一个临时保存表单的会话,然后在他们登录后保存到数据库。但是我很困惑如何编写代码

任何人都可以解释一下 django 会话是什么样的吗?以及如何编写代码来处理这个问题?

You can try something like,

1 User fills out the form and hits submit

2 in the POST view where you handle the form, use the "**is_authenticated**" function and, 
    a)if the user is authenticated you handle the form as usual...
    b)else set the contents of the form into a session variable in the views and redirect to the login page like,

request.session['review_body'] = request.post.get(the_form_body_field)

3 as per what you've said, after login it goes to profile page and form is submitted...
    a)so in views where you serve the profile page, check if the session variable containing form data's exist and has values
    b)if yes, directly save the contents from your views and clear the session data