[Zope] Setting a Cookie
Randall F. Kern
randy@spoke.net
Fri, 18 May 2001 16:21:51 -0700
Here's the code I use from python:
RESPONSE.setCookie('cookiename', 'cookie value', path=3D'/',
expires=3D'Sunday 20-05-001 12:00:00 GMT')
Or, with no expiration:
RESPONSE.setCookie('cookiename', 'cookie value', path=3D'/')
To do this from DTML would look like:
<dtml-call expr=3D"RESPONSE.setCookie('cookiename', 'cookie value',
path=3D'/', expires=3D'Sunday 20-05-001 12:00:00 GMT')">
Or:
<dtml-call expr=3D"RESPONSE.setCookie('cookiename', 'cookie value',
path=3D'/')">
This works fine in python 1.5.2, zope 2.3.1.
-Randy
FYI, the 4th parameter is self, an implicit parameter to a python
method.
> -----Original Message-----
> From: Tommy Johnson [mailto:tommy@7x.com]
> Sent: Friday, May 18, 2001 4:12 PM
> To: zope@zope.org
> Subject: [Zope] Setting a Cookie
>=20
>=20
> Hey all,
>=20
> I'm trying to set a cookie. Simple right? hehe - if so, then=20
> I wouldn't=20
> be here. ;-)
>=20
> Ok, I have the syntax in front of me. I have this bit of code to set=20
> the cookie:
>=20
> <dtml-call "RESPONSE.setCookie('CookieMonster', '458468')">
>=20
> All is well when I save the dtml document and when I run the=20
> page. The=20
> problem - the cookie isn't set!
>=20
> Now I remember this problem when I worked with ASP. It turns out that=20
> you had to set an expire date also (although they said that if you=20
> didn't, the cookie expires when you close the browser and=20
> nothing gets=20
> written to the client machine.) That would be good - IF ONLY I COULD=20
> ACCESS THE INFORMATION I SET.
>=20
> Sorry 'bout that. But it's fustrating to see this problem=20
> come up again=20
> with another language.
>=20
> So I set an expire date. But, get this, now it fails when the page is=20
> loaded. The error message says that the method expected three=20
> parameters, but received four. Do you see four parameters here?
>=20
> <dtml-call "RESPONSE.setCookie('CookieMonster', '458468',=20
> 'Sunday 20-05-
> 2001 12:00:00 GMT')">
>=20
> I initially had a comma between Wdy, Date - because that is the=20
> DOCUMENTED syntax, but this seems incorrect also.
>=20
> Here's the error message:
>=20
> Error Type: TypeError
> Error Value: too many arguments; expected 3, got 4
>=20
> Any suggestions? Proven code would be appreciated.
>=20
> Thanks in advance,
> Tommy
>=20
>=20
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -=20
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>=20