Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django SESSION_COOKIE_DOMAIN on localhost

When I set SESSION_COOKIE_DOMAIN = '.mysite.com' and then run the production site, the site creates the proper cross domain cookie and it's set to .mysite.com. However, if I set SESSION_COOKIE_DOMAIN = '.localhost' and run the local development server at localhost:8000 the cookie that is created is the non-cross domain cookie localhost.

Why might this be the case?

Thanks.

like image 541
Etan Avatar asked Jul 12 '11 21:07

Etan


1 Answers

This has to do with how browsers and cookies work. Because you're not allowed to set cookies to something like .com, you can't set it as .localhost either.

You can check out more here: https://code.djangoproject.com/ticket/10560. Looks like there's no real solution within Django for this. I do wish they would warn us though rather than just break.

I don't have a good solution though. For testing you could set your hosts file to use something like test.com instead of localhost to point to your runserver.

like image 88
Jeff Avatar answered Sep 20 '22 03:09

Jeff