簡體   English   中英

使用龍卷風獲取Cookies StaticFileHandler

[英]get cookies with tornado StaticFileHandler

我要在獲取某些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?

謝謝

龍卷風文檔警告不要重寫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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM