Kit*_*Kit 5 python cookies cherrypy
从CherryPy 文档中,似乎只有一个cookie插槽.这是我的示例代码
def sendCookie(self):
cookie = cherrypy.response.cookie
cookie['name'] = 'Chips Ahoy!'
return 'Cookie is now in your hands.'
sendCookie.exposed = True
Run Code Online (Sandbox Code Playgroud)
我想设置多个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
Run Code Online (Sandbox Code Playgroud)
如何使用CherryPy设置多个cookie?
我认为第一个键cookie应该对应于cookie的名称,其中附加键对应于该cookie的属性.因此,'name'您应该使用一些唯一的名称,而不是用作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
Run Code Online (Sandbox Code Playgroud)
那样有用吗?
编辑:糟糕,每个morsel都有一组预定义的属性,我在那里定义自己的('shape'和'count').现在应该修好.
| 归档时间: |
|
| 查看次数: |
1505 次 |
| 最近记录: |