django会话变量在不同选项卡中的不同值

问题描述:

请考虑以下情形:

  1. 用户搜索内容并创建一个列表(request.session ['List'])
  2. 用户可以通过ajax调用过滤此列表
  3. 现在用户打开一个新选项卡,进行另一次搜索,因此现在将会话变量List设置为新列表以进行其他搜索
  4. 用户返回第一个选项卡,然后再次过滤结果.这次,随着会话变量的更改,过滤结果来自另一个标签中的新列表

是否可以为不同选项卡的会话变量设置不同的值?或任何其他解决此问题的方法?

Is there a way to set different values for a session variable for different tabs? or any other solution for this problem?

没有简单的方法可以做到这一点,并且它不是Django特有的.检查以下问题:

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

如何在浏览器标签中区分会话?.

基于cookie的会话不一定能正常工作,因为cookie在特定站点的选项卡之间是常见的.基于具有会话或本地存储的URL的解决方案有其自身的问题,通常这不是一个好主意,因为它增加了大多数情况下不需要的复杂性.

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.

在您的情况下,为什么不将列表存储为JavaScript数据或本地存储?在这种情况下,每个选项卡都有其自己的数据.

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.