Django SESSION_COOKIE_DOMAIN on localhost

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.


for dev server, you can just use

SESSION_COOKIE_SECURE= False #default use just to override your prod setting
SESSION_COOKIE_DOMAIN= None  #default  use just to override your prod setting

or you can resolve domain name with the host's file

 SESSION_COOKIE_DOMAIN= '.localhost'

Or something like this

SESSION_COOKIE_SECURE= False
SESSION_COOKIE_DOMAIN=  "127.0.0.1"