出于某种原因,我无法在 MainHandler 之外实例化 set_cookie .. 这是一个小代码来显示我想要做什么.. 任何人都可以帮忙吗?
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
from GenCookie import *
class MainHandler(tornado.web.RequestHandler):
def get(self):
g=GenCookie()
response = g.genCookie()
class GenCookie:
def genCookie(self):
print self.request.remote_ip
print self.cookies
print self.request.headers
expires = datetime.datetime.utcnow() + datetime.timedelta(days=365)
if ("uid" in cookies):
self.set_cookie("uid", value=cookies["uid"],expires=expires)
else:
self.set_cookie("uid", value='dfc278623ab44df2bd501e106e81d146',expires=expires)
return
有任何想法吗?