6

我登录到 django 管理员。当我打开firebug JS 控制台并尝试打印 cookie 时,document.cookie我只得到csrftokencookie。但是当我打开 Firefox 首选项 > 隐私 > 删除 cookie... 时,我可以看到sessionidcookie。

如何在客户端获得它?

4

1 回答 1

11

您无法访问会话 cookie,因为它默认设置为 HTTPOnly。(您可以使用 Firebug 看到它(Resources->Cookies->sessionid 的 HTTP 列已选中))

文档复制:

SESSION_COOKIE_HTTPONLY
Default: True

Whether to use HTTPOnly flag on the session cookie. 
If this is set to True, client-side JavaScript will not to 
be able to access the session cookie.

SESSION_COOKIE_HTTPONLY = False如果您真的想从客户端代码访问它,您可以在您的 settings.py 中设置:尽管如此,这不是推荐的做法。

于 2012-09-15T10:41:52.833 回答