From djangoproject, HttpResponse.set_cookie(key, value=”, max_age=None, expires=None, path=’/’, domain=None, secure=None, httponly=True)
There is not a good description of what the path variable does. I was wondering what it does and whether I need to set it. Does it relate at all to url resolver?
my urls look like this:
- /a
- /a/b
- /a/c
I don’t have any at the root. Should I set path to ‘/a’ ?
http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Path
It’s a way to define under what parts of the site the cookie should be set for (and is part of HTTP, not Django specifically). So, if you want the Cookie to be sent back for the entire website, leave the path as
/, but if you only want it to work on, let’s say, your Forum, and your Forum is located at/forum, then that’s what you would set Path to.Specifically to your question, just because you don’t have any views/urls at
/, you can still set the cookie path to/which will make it work site-wide. If everything on your site is always after/a, then you could also use that and you wouldn’t notice a difference.