When using subdomains for a Django site, how can you share django inputs through subdomains on localhost?

I want the same user session session: site.com
sub1.site.com
sub2.site.com

How can I do this in Django? With the default user auth package, it seems to require the user to go to all 3 sites each time with a different session. How can they use the same cookie to log in and session ID?

UPDATE: using the SESSION_COOKIE_DOMAIN value in settings.py seems to work on production sites, but it does not work for me on localhost / dev servers. How to make it work in local subdomains? When I change SESSION_COOKIE_DOMAIN to the website name or ".localhost", django auth authorizers completely stop working (I cannot log in, the cookie is not created on localhost.)

+6
django django-authentication
source share
1 answer

I think I have a workaround, but cannot use localhost. I could make it work only for the .com test domain, which corresponds to 127.0.0.1.

In my / etc / hosts file (on OSX :)

  127.0.0.1 test.com
     127.0.0.1 sub1.test.com
     127.0.0.1 sub2.test.com 

Then on my setup settings.py:

  SESSION_COOKIE_DOMAIN = ". Test.com"

I could not get this to work with a simple "localhost", it seemed to me that I needed the string ".com" to make it work. That way I can log in and cross with subdomain cookies using sub1.test.com:8000 and sub2.test.com:8000 in my browser.

+12
source share

All Articles