其他分享
首页 > 其他分享> > cherrypy cookies

cherrypy cookies

作者:互联网

code

import cherrypy


class MyCookieApp(object):
    @cherrypy.expose
    def set(self):
        cookie = cherrypy.response.cookie
        cookie['cookieName'] = 'cookieValue'
        cookie['cookieName']['path'] = '/'
        cookie['cookieName']['max-age'] = 3600
        cookie['cookieName']['version'] = 1
        return "<html><body>Hello, I just sent you a cookie</body></html>"


    @cherrypy.expose
    def read(self):
        cookie = cherrypy.request.cookie
        res = """<html><body>Hi, you sent me %s cookies.<br />
                Here is a list of cookie names/values:<br />""" % len(cookie)
        for name in cookie.keys():
            res += "name: %s, value: %s
" % (name, cookie[name].value)
        return res + "</body></html>"


if __name__ == '__main__':
    cherrypy.quickstart(MyCookieApp(), '/cookie')

 

 

 

 

 

 

 

 

 

 

标签:__,cookies,name,cherrypy,res,cookieName,cookie
来源: https://www.cnblogs.com/sea-stream/p/14179400.html