Python- Bottle - Cookies Keep Changing
Below is my code for setting and reading cookies in bottle. if request.get_cookie('mycookiename'): cookie_id = request.get_cookie('mycookiename') else: cookie_i
Solution 1:
This code works. You set a new value cookie with uuid4 if you have not a cookie already define.
In your code, i guess your "else" condition is bad.
# -*- coding: utf-8 -*-#!/usr/bin/env pythonfrom uuid import uuid4
import bottle
@bottle.route('/cookie')defcookie():
cookie_id = bottle.request.get_cookie('mycookiename', str(uuid4()))
bottle.response.set_cookie('mycookiename', cookie_id)
return'hello cookie'if __name__ == '__main__':
bottle.run(host='localhost', port=8080)
Post a Comment for "Python- Bottle - Cookies Keep Changing"