In one view, I set:

在一个视图中,我设置:

request.session.set_expiry(999)
request.session['test'] = '123'

In another view, I do:

在另一种观点中,我这样做:

print request.session['test']

and it cannot be found. (error) It's very simple, I just have 2 views.

它无法找到。 (错误)这很简单,我只有2个视图。

It seems that once I leave a view and come back to it...it's gone! Why?

似乎一旦我离开了一个观点并回到它......它已经消失了!为什么?

2 个解决方案

#1


14

Could it be related to this?, just found it at http://code.djangoproject.com/wiki/NewbieMistakes

可能与此有关吗?只是在http://code.djangoproject.com/wiki/NewbieMistakes找到它?

Appending to a list in session doesn't work Problem

在会话中附加到列表不起作用问题

If you have a list in your session, append operations don't get saved to the object. Solution

如果会话中有列表,则追加操作不会保存到对象中。解

Copy the list out of the session object, append to it, then copy it back in:

将列表复制出会话对象,附加到该对象,然后将其复制回:

sessionlist = request.session['my_list']
sessionlist.append(new_object)
request.session['my_list'] = sessionlist

更多相关文章

  1. Python Flask WTForms:如何在视图中动态禁用字段?
  2. Python列表以及列表的处理方法
  3. python入门之常见列表、字典知识
  4. 如何使用不同的类python在一个类中的一个窗口中更新列表框
  5. python打印列表的下标和值的例子:
  6. 使用python如何在列表列表中找到元素,而关键元素是内部列表的元素
  7. Python学习记录--关于列表和字典的比较
  8. 如何将两个列表中的数据写入csv中的列?
  9. 在python 3.3列表中查找最小值

随机推荐

  1. 数据库中间件 Sharding-JDBC 源码分析 —
  2. 招聘|北京字节跳动科技有限公司
  3. 【招聘】杭州蘑菇街招高级前端
  4. 盘点2015年前端早读课专访
  5. 专访|360奇舞团团长@月影
  6. 专访|美的电商高级前端工程师@姬小光
  7. 一文带你学会AQS和并发工具类的关系2
  8. 盘点2015年前端工程师必备图书@前端早读
  9. 【招聘】北京计蒜客招初/中级前端工程师
  10. 【招聘】西安瑞木招web前端