【问题标题】:How to save (temporarily) form data?如何保存(临时)表单数据?
【发布时间】:2012-02-28 14:30:51
【问题描述】:

例如,page1 上有 10 个字段和指向 page2 的超链接。 page2 上还有指向 page1 的超链接。我填写 5 个字段并单击超链接。然后我点击page2上的超链接,返回page1。是否可以保存填写的字段以及如何保存? 附加问题:如果 page2 修改了 page1 的字段怎么办。例如,在多选字段中创建新的选择。

【问题讨论】:

    标签: django


    【解决方案1】:

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

    编辑 1#

    检查这些问题:Django Passing data between viewsHow do you pass or share variables between django views?

    【讨论】:

    • 我不需要拆分表格。问题在于单击链接时执行操作。是否只有 JavaScript 或 Django 有特殊功能?
    • 你的问题在stackoverflow上已经有了一些答案。
    • 主要问题不是保存数据,而是在点击链接时保存数据。据我所知,如果没有 JavaScript,这是不可能的。无论如何,谢谢。
    【解决方案2】:

    您可以在点击链接后通过 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.
    

    【讨论】:

      猜你喜欢
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多