当用户获取一些js静态文件时,我想获取用户的会话cookie:
class StaticFileHandler(web.StaticFileHandler):
@gen.coroutine
def get(self, path):
print ('got JS request from %s' % self.request.remote_ip)
print ('request.cookies : %s' % self.request.cookies)
super(StaticFileHandler, self).get(path)但是,cookie始终是None的,即使我可以在浏览器中看到它设置了会话cookie。
我在这里做错了什么?在提供这样的静态文件时,获取cookie是不可能的吗?
谢谢
发布于 2014-12-31 18:54:30
tornado文档警告不要重写StaticFileHandler get方法:http://tornado.readthedocs.org/en/latest/web.html#tornado.web.StaticFileHandler
“子类只能重写本节中讨论的方法;重写其他方法容易出错。由于与compute_etag和其他方法的紧密耦合,重写StaticFileHandler.get尤其有问题。”
我建议您尝试覆盖StaticFileHandler类的get_content方法:
http://tornado.readthedocs.org/en/latest/web.html#tornado.web.StaticFileHandler.get_content
https://stackoverflow.com/questions/27647290
复制相似问题