如何保存(临时)表格数据?

时间:2012-02-07 05:48:36

标签: django

例如,第1页上有10个字段,第2页上有超链接。第2页到第1页也有超链接。我填写5个字段,然后单击超链接。然后我点击第2页上的超链接并返回第1页。是否可以保存填充的字段以及如何? 其他问题:如果page2修改page1的字段该怎么办?例如,在multichoice字段中创建新选项。

2 个答案:

答案 0 :(得分:2)

Django已经实施了允许在多个网页上拆分表单的解决方案。它被称为表单向导。检查here以获取教程。

编辑1#

请查看以下问题:Django Passing data between viewsHow do you pass or share variables between django views?

答案 1 :(得分:1)

点击链接后,在转到其他页面之前,您可以通过javascript使用Cookie保存填充的字段。例如,可以使用此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.