Python – Django multi-session cookie domain for multiple subdomains

Django multi-session cookie domain for multiple subdomains… here is a solution to the problem.

Django multi-session cookie domain for multiple subdomains

My Django application handles multiple subdomains like “first.domain.com”, “second.domain.com”, etc.

My SESSION_COOKIE_DOMAIN is “.domain.com” to handle multiple subdomains.

So when I access my app from first.domain.com or second.domain.com, I can see the same session cookie from both subdomains.

So my question is; Is it possible to set SESSION_COOKIE_DOMAIN to “first.domain.com” when accessing from “first.domain.com” and “second.domain.com”, is it accessed from “second.domain.com”?

Solution

Just remove the SESSION_COOKIE_DOMAIN setting or set it to None. Django will automatically use the current domain.

Related Problems and Solutions