在Django,我的request.session没有结束......有谁知道为什么?
16lz
2021-01-22
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
更多相关文章
- Python Flask WTForms:如何在视图中动态禁用字段?
- Python列表以及列表的处理方法
- python入门之常见列表、字典知识
- 如何使用不同的类python在一个类中的一个窗口中更新列表框
- python打印列表的下标和值的例子:
- 使用python如何在列表列表中找到元素,而关键元素是内部列表的元素
- Python学习记录--关于列表和字典的比较
- 如何将两个列表中的数据写入csv中的列?
- 在python 3.3列表中查找最小值