2024-10-01 07:48:27 发布
网友
我正在尝试使用Flask设置一个与列表相等的cookie
这就是我想要达到的目标
resp = make_response(render_template('home.html')) cookiePayload = [userName, rights] resp.set_cookie('username', cookiePayload) return resp
但它给我带来了一些打字错误。怎么了
以下是set_cookie方法的文档:
set_cookie
Sets a cookie. The parameters are the same as in the cookie Morsel object in the Python standard library but it accepts unicode data, too.
https://flask.palletsprojects.com/en/1.1.x/api/#flask.Response.set_cookie
因此,您需要将这些列表转换为字符串。实现这一点的方法之一是将列表转换为json对象
让我们看看行动
import json resp = make_response(render_template('home.html')) cookiePayload = [userName, rights] resp.set_cookie('username', json.dumps(cookiePayload)) return resp
以下是
set_cookie
方法的文档:https://flask.palletsprojects.com/en/1.1.x/api/#flask.Response.set_cookie
因此,您需要将这些列表转换为字符串。实现这一点的方法之一是将列表转换为json对象
让我们看看行动
相关问题 更多 >
编程相关推荐