开发者

In Django, my request.session is not carrying over...does anyone know why?

开发者 https://www.devze.com 2022-12-18 22:01 出处:网络
In one view, I set: request.session.set_expiry(999) request.session[\'test\'] = \'123\' In an开发者_高级运维other view, I do:

In one view, I set:

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

In an开发者_高级运维other view, I do:

print request.session['test']

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

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


Could it be related to this?, just found it at 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


Are you, by any chance, setting the session itself to an empty dictionary, somewhere?

0

精彩评论

暂无评论...
验证码 换一张
取 消