且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在特定子域上共享 django 会话

更新时间:2023-11-27 23:04:58

解决方案是设置

SESSION_COOKIE_DOMAIN = '.example.com'

重命名会话cookie名称,例如

and rename the session cookie name, e.g.

SESSION_COOKIE_NAME = 'examplesessionid'

在驱动两个子域的 Django 实例上.这两个站点将使用具有全局范围的重命名的 cookie,并且不会干扰其他 Django 实例,在各自的子域中使用默认的sessionid"cookie.

on the Django instance that is driving the two subdomains. The two sites will use the renamed cookie with a global scope and not interfere with the other Django instances, using the default 'sessionid' cookie on their respective subdomains.

请注意,cookie 发送到 example.com 子域上的其他 Django 实例,但不会被解释为 Django 会话 cookie.

Note that the cookie will be sent to the other Django instances on subdomains of example.com, but will not be interpreted as a Django session cookie.