Django SESSION_COOKIE_DOMAIN on localhost

When I set SESSION_COOKIE_DOMAIN = '.mysite.com' and then run the production site, the site creates the correct cookie for the cross domain and is set to .mysite.com . However, if I set SESSION_COOKIE_DOMAIN = '.localhost' and run the local development server in localhost:8000 , the cookie created is a non-overlapping localhost cookie.

Why could this be so?

Thanks.

+4
source share
1 answer

This is due to how browsers and cookies work. Since you cannot set cookies on something like .com, you also cannot set it as .localhost.

You can find out more here: https://code.djangoproject.com/ticket/10560 . There seems to be no real solution in Django for this. I would like them to warn us, and not just break.

I have no good solution. For testing, you can configure the hosts file to use something like test.com instead of localhost to point to your server.

+7
source

All Articles