From CherryPy documentation, there seems to be only one cookie slot. Here's my example code
def sendCookie(self):
cookie = cherrypy.response.cookie
cookie['name'] = 'Chips Ahoy!'
return 'Cookie is now in your hands.'
sendCookie.exposed = True
I want to set multiple cookies. I'm thinking along these lines, but of course this will just overwrite the first setting.
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
How do I set multiple cookies with CherryPy?
I think the first key in cookie
should correspond to the name of the cookie, where additional keys would correspond to attributes of that cookie. Thus, instead of using 'name'
as the key for your cookies, you should use some unique name.
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
Does that work?
Edit: Oops, each morsel
has a predefined set of properties, where I was defining my own ('shape'
and 'count'
). Should be fixed now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With