【发布时间】:2012-02-28 14:30:51
【问题描述】:
例如,page1 上有 10 个字段和指向 page2 的超链接。 page2 上还有指向 page1 的超链接。我填写 5 个字段并单击超链接。然后我点击page2上的超链接,返回page1。是否可以保存填写的字段以及如何保存? 附加问题:如果 page2 修改了 page1 的字段怎么办。例如,在多选字段中创建新的选择。
【问题讨论】:
标签: django
例如,page1 上有 10 个字段和指向 page2 的超链接。 page2 上还有指向 page1 的超链接。我填写 5 个字段并单击超链接。然后我点击page2上的超链接,返回page1。是否可以保存填写的字段以及如何保存? 附加问题:如果 page2 修改了 page1 的字段怎么办。例如,在多选字段中创建新的选择。
【问题讨论】:
标签: django
Django 已经实现了允许在多个网页上拆分表单的解决方案。它被称为表单向导。查看here 获取教程。
编辑 1#
检查这些问题:Django Passing data between views,How do you pass or share variables between django views?
【讨论】:
您可以在点击链接后通过 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.
【讨论】: