我正在使用Django签名的cookie引擎来存储会话数据。我的设置是:
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
SESSION_COOKIE_NAME = 'sessionid'
它可以正常工作。即使在我访问网站时关闭浏览器和Web服务器,我仍然登录。我可以看到sessionid已设置但我似乎无法找到会话数据的存储位置。我在会话中存储整个用户对象。
答案 0 :(得分:1)
数据存储在def _get_session_key(self):
"""
Instead of generating a random string, generate a secure url-safe
base64-encoded string of data as our session key.
"""
return signing.dumps(
self._session, compress=True,
salt='django.contrib.sessions.backends.signed_cookies',
serializer=self.serializer,
)
本身。以下是已签名的Cookie后端的相关source code:
type Symbol =
| Seven
| Eight
| Nine
| Ten
| Jack
| Queen
| King
| Ace
type Suit =
| Heart
| Diamond
| Spade
| Club
type Card = { suit: Suit; rank: Rank }
let getValue (card:Card) =
match card.rank with
| Seven | Eight | Nine -> 0
| Ten -> 10
...