different values of a django session variable in different tabs

。_饼干妹妹 提交于 2019-12-06 11:06:28
maulik13

There is no easy way to do this and it's not Django specific. Check this question:

How to differ sessions in browser-tabs?.

Session based on cookie will not certainly work as cookie is common between tabs for a specific site. Solutions based on URLs with session or local storage have their own issues and in general this is not a good idea because it adds a complexity that is not required in most cases.

In your case, why don't you store the list as JavaScript data or local storage? In that case each tab has its own data.

The server application identifies your requests and session by your session ID, this means that it does not know about tabs and such. In fact, if you give me your session ID, I will get the same list(see Session Hijacking not to get into such troubles).

That being said, if you really want to do that, you could play around with saving user-agent into your session, or make use of request.is_ajax()

You could have session['List'] = ... and session['List_ajax'] = ...` Then you whould do: return session['List_ajax'] if request.is_ajax() else sessoion['List']

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!