在特定子域上共享 django 会话 [英] Sharing django sessions on specific subdomains

查看:18
本文介绍了在特定子域上共享 django 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 example.com 和 support.example.com .如果用户在主站点上登录,我希望可以从支持站点访问会话.

I have example.com and support.example.com . If a user is logged in on the main site, I'd like to have the session be accessible from the support site.

将 SESSION_COOKIE_DOMAIN 设置为 '.example.com' 不是我想要的,因为我有许多其他带有 django 应用程序的子域,但我不想访问会话.

Setting the SESSION_COOKIE_DOMAIN to '.example.com' isn't what I want because I have many, many other subdomains with django apps that I would like to NOT have access to the session.

目前我唯一能想到的解决方法是棘手的重定向,如有必要,我想避免这种情况.

Currently my only conceivable workaround involves tricky redirects, which I'd like to avoid if necessary.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

解决方案是设置

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.

这篇关于在特定子域上共享 django 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆