Sharing django sessions on specific subdomains

后端 未结 6 1092
深忆病人
深忆病人 2020-12-05 00:29

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.

Setting the

6条回答
  •  醉酒成梦
    2020-12-05 01:09

    The solution would be to set

    SESSION_COOKIE_DOMAIN = '.example.com'
    

    and rename the session cookie name, e.g.

    SESSION_COOKIE_NAME = 'examplesessionid'
    

    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.

    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.

提交回复
热议问题