python cookies 中多个 相同 的健和键值_python – 如何使用CherryPy设置多个cookie

从CherryPy documentation开始,似乎只有一个cookie插槽.这是我的示例代码

def sendCookie(self):

cookie = cherrypy.response.cookie

cookie['name'] = 'Chips Ahoy!'

return 'Cookie is now in your hands.'

sendCookie.exposed = True

我想设置多个cookie.我正在考虑这些问题,但当然这只会覆盖第一个设置.

def sendCookie(self):

cookie = cherrypy.response.cookie

cookie2 = cherrypy.response.cookie

cookie['name'] = 'Chips Ahoy!'

cookie2['name'] = 'Chocolate Chips'

return 'Cookie is now in your hands.'

sendCookie.exposed = True

如何使用CherryPy设置多个cookie?

解决方法:

我认为cookie中的第一个键应该对应于cookie的名称,其中附加键对应于该cookie的属性.因此,您应该使用一些唯一的名称,而不是使用“名称”作为Cookie的密钥.

def sendCookie(self):

cookies = cherrypy.response.cookie

cookies['cookie1'] = 'Chips Ahoy!'

cookies['cookie1']['path'] = '/the/red/bag/'

cookies['cookie1']['comment'] = 'round'

cookies['cookie2'] = 'Chocolate Chips'

cookies['cookie2']['path'] = '/the/yellow/bag/'

cookies['cookie2']['comment'] = 'thousands'

return 'Cookies are now in your hands.'

setCookie.exposed = True

那样有用吗?

编辑:哎呀,每个morsel都有一组预定义的属性,我在那里定义了自己的属性(‘shape’和’count’).现在应该修好.

标签:python,cookies,cherrypy

来源: https://codeday.me/bug/20190521/1146667.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值