gpt4 book ai didi

python - 如何在 Django 中为多值 cookie 指定分隔符?

转载 作者:太空宇宙 更新时间:2023-11-04 01:26:39 24 4
gpt4 key购买 nike

在 Django 中创建多值 cookie 时,如何指定每个键/值对之间的分隔符,以便 cookie 接收分隔符的 ASCII 字符表示而不是其八进制表示?这是我目前正在做的事情:

uid = 1
dev = 'computer'
cookie_value = 'uid:%s,dev:%s' % (uid, dev)
response.set_cookie(key="profile", value=cookie_value)

如果我通过 Python 调试器运行它,cookie_value 包含:

'uid:1,dev:computer'

但是,如果我在浏览器中检查 cookie,我会看到:

'uid:1\054dev:computer'

如何让 Django 将 '\054' 替换为逗号?

谢谢。

最佳答案

你的答案是here

Cookie encoding

To fix bugs with cookies in Internet Explorer, Safari, and possibly other browsers, our encoding of cookie values was changed so that the characters comma and semi-colon are treated as non-safe characters, and are therefore encoded as \054 and \073 respectively. This could produce backwards incompatibilities, especially if you are storing comma or semi-colon in cookies and have javascript code that parses and manipulates cookie values client-side.

关于python - 如何在 Django 中为多值 cookie 指定分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17355358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com