Reputation: 78352
I am trying to setup a cookie on my dev machine using localhost. Below is my web.py code. But, when I run the code in te bowser at http://0.0.0.0:8080/ I get a page but no cookie was set. FYI hostname --fqdn is equal to "ubuntu". This is my first time trying to set a cookie. I also tried ubuntu, 127.0.0.1 as well as the doman.
class index:
def GET(self):
env = web.ctx['environ']
qs = urlparse.parse_qs(env['QUERY_STRING'])
#Set cookie
web.setcookie('test', "rtb", expires=3600, domain='localhost', secure=False)
return 'test'
Upvotes: 1
Views: 1292
Reputation: 11862
Your example seems to work just fine. Using Firebug I can see the cookie in the response just fine:
test=rtb; Domain=localhost; expires=Wed, 15-Feb-2012 20:08:02 GMT; Path=/
By they way, try to include the full context for your code whenever possible. I tested your snippet because I know how to set up a basic web.py app, that urlparse lives in urllib2, etc. But you'll get more responses to your questions if you make it easier for people to help you.
You can retrieve the cookie by adding a class like the following (remember linking it to another path in your routes list):
class cookie:
def GET(self):
cookie = web.cookies().get('test')
return cookie
Upvotes: 2