且构网

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

在特定子域上共享django会话

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

解决方案是设置

SESSION_COOKIE_DOMAIN = '.example.com'

并重命名会话cookie名称,例如

and rename the session cookie name, e.g.

SESSION_COOKIE_NAME = 'examplesessionid'

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

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.

请注意,系统会将 发送到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.