如何保存(临时)表单数据



例如,第1页有10个字段,第2页有超链接。还有第2页到第1页的超链接。我填写了5个字段,然后点击超链接。然后我点击第2页的超链接,返回第1页。是否可以保存已填充的字段以及如何保存?附加问题:如果第2页修改了第1页的字段,该怎么办。例如,在多选项字段中创建新选项。

Django已经实现了允许在多个网页上拆分表单的解决方案。它被称为表单向导。查看此处了解教程。

编辑1#

查看以下问题:Django在视图之间传递数据,如何在Django视图之间传递或共享变量?

您可以在点击链接后,在转到另一个页面之前,通过javascript保存已填充的字段。例如,可以使用这个jQuery插件jQuery cookie。如文件所示:

A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
Create session cookie:
$.cookie('the_cookie', 'the_value');
Create expiring cookie, 7 days from then:    
$.cookie('the_cookie', 'the_value', { expires: 7 });
Create expiring cookie, valid across entire page:    
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
Read cookie:    
$.cookie('the_cookie'); // => 'the_value'
$.cookie('not_existing'); // => null
Delete cookie by passing null as value:    
$.cookie('the_cookie', null);
Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie.

最新更新