[英]Django: Cannot access sessionid cookie using Javascript
I tried using several mechanisms, including the jquery cookie plugin. 我尝试使用几种机制,包括jquery cookie插件。 When I try to read this cookie, I always get an empty result.
当我尝试读取这个cookie时,我总是得到一个空的结果。 Chrome's Developer Console shows that the sessionid cookie is indeed set.
Chrome的开发者控制台显示确实设置了sessionid cookie。 However, there's a checkmark for the HTTP column for that cookie, which is different than the other cookies.
但是,该cookie的HTTP列有一个复选标记,与其他cookie不同。 I'm developing on my localhost, if that makes a difference.
我正在开发我的本地主机,如果这有所作为。
It's a HTTP-only cookie; 这是一个仅限HTTP的cookie; they cannot be read by JavaScript.
它们无法被JavaScript读取。
http://en.wikipedia.org/wiki/HTTP_cookie#Secure_and_HttpOnly http://en.wikipedia.org/wiki/HTTP_cookie#Secure_and_HttpOnly
It's explained in the documentation about sessions: 有关会话的文档中对此进行了解释:
https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions
The behavior can be changed by setting SESSION_COOKIE_HTTPONLY
to false (but that is not recommended; see link above). 可以通过将
SESSION_COOKIE_HTTPONLY
设置为false来更改行为(但不建议这样做;请参阅上面的链接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.