我目前正在尝试使用 Brython 处理 cookie,但遇到了一些麻烦。我local_storage
在文档中找到了该模块。当我使用此模块设置 cookie 时,服务器找不到它们(request.COOKIES
在 Djangoviews.py
函数中使用)。奇怪的是,该值已存储,因为当我重新加载页面时,脚本会在控制台中打印它。
HTML页面中的代码:
<script type="text/python">
from browser.local_storage import storage
import random
if 'test' in storage:
print(storage['test'])
storage['test'] = str(random.randint(0, 100))
print(storage['test'])
</script>
每次我重新加载页面时,我得到的值是已存储但 cookie 在服务器端不存在的值(request.COOKIES
不包含密钥'test'
)。
也许我缺少一些东西?
编辑:
因此,在查看此页面(来自 Brython 文档的链接)https://html.spec.whatwg.org/multipage/webstorage.html后,我发现本地存储与 cookie 不同,而是存在类似的系统并排。
所以我现在的问题是如何将 cookie 与 Brython 一起使用而不是本地存储?