python - 我的 cookie 阅读器不工作
问题描述
所以,我在网上找不到任何真正可以读取 cookie 的 Python 3 脚本。这是代码(解释后面的内容);
red_theme = "red_style.css"
blue_theme = "blue_style.css"
green_theme = "green_style.css"
dark_theme = "dark_style.css"
light_theme = "light_style.css"
### COOKIE WRITER + THEME SETTINGS
jar = Cookie.SimpleCookie()
if data.getvalue("t") == "red":
theme = red_theme
jar['s_theme']=red_theme
if data.getvalue("t") == "blue":
theme = blue_theme
jar['s_theme']=blue_theme
if data.getvalue("t") == "green":
theme = green_theme
jar['s_theme']=green_theme
if data.getvalue("t") == "dark":
theme = dark_theme
jar['s_theme']=dark_theme
if data.getvalue("t") == "light":
theme = light_theme
jar['s_theme']=light_theme
else:
theme = red_theme
jar['s_theme']=red_theme
### COOKIE READER
try:
jar = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"])
theme = jar["s_theme"].value
except (Cookie.CookieError, KeyError):
theme = "error.css"
此脚本查找您是否将 ?t=***** 作为某个主题(红色、绿色、蓝色......等)。然后在该信息上,它将一个 cookie(jar)写入 [s_theme = colour] 但是...读取的脚本不起作用。
### COOKIE READER
try:
jar = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"])
theme = jar["s_theme"].value
except (Cookie.CookieError, KeyError):
theme = "error.css"
在 HTML 代码之后;它这样做:
<link rel="stylesheet" href=\"""" + theme + """\">
总之; 尝试制作一个主题设置器,根据您选择的默认主题设置,因此如果您转到https://...?theme=dark,它会将您的默认主题设置为深色。但是...我无法使用阅读脚本。
真的很感谢你的帮助 - Reefive
解决方案
推荐阅读
- flutter - 将 Flutter 升级到 2.5.0 后 textDirection 不起作用
- keycloak - 如何使用 kcadm 在 keycloak 中启用更新密码的默认操作?
- install4j - 在索引向导中使用编译器变量作为键不起作用
- mysql - 如何从 3 个不同的表中获取 5 个值?[MYSQL]
- apache-kafka - Ksqldb 从整数解析日期
- go - golang我如何使用结构名称作为映射键
- javascript - 在 webpack 项目中注册 Service Worker 会出现 404
- algorithm - 有人可以解释这个问题陈述的方法。我被困住了
- apache-kafka - kafka 连接没有可用分配的消费者组成员
- python - 在实际值之上绘制 auto_arima 预测