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
#2
0
Are you, by any chance, setting the session itself to an empty dictionary, somewhere?
在任何可能的情况下,您是否将会话本身设置为空字典?
#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
#2
0
Are you, by any chance, setting the session itself to an empty dictionary, somewhere?
在任何可能的情况下,您是否将会话本身设置为空字典?