David,

It looks like you are trying to get the cookie before you set it. I
believe the way you have it currently, the cookie will never be set,
as an exception will be thrown before it gets to the point in the
script where it will be set.

You can either move the web.setcookie() call to before
"cookie=web.cookies().get('test')", or, if you want to always try and
retrieve it first, do,

try:
     cookie = web.cookies().get('test')
except AttributeError: #I think it's an AttributeError, anyway.
     web.setcookie([...])

On Feb 11, 2:12 pm, David Montgomery <[email protected]>
wrote:
> Hi,
>
> I am trying to set a cookie using the below.  Should it not work on
> localhost?  I also tried localhost.localdomain.
>
> So..did I set a cookie correct?  If I go back to the page should I
> then should to read the cookie?
>
> I am a cookie newbie.
>
> class index:
>     def GET(self):
>         env = web.ctx['environ']
>         qs = urlparse.parse_qs(env['QUERY_STRING'])
>
>         #Get cookie
>         cookie = web.cookies().get('test')
>         #Set cookie
>
>         web.setcookie('test', "rtb", expires=3600, domain='localhost',
> secure=False)
>
>         return "<html></html>"
>
> Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to