静态文件和文件缓存

  1、在应用配置 settings 中指定 static_path 选项来提供静态文件服务;

    2、在应用配置 settings 中指定 static_url_prefix 选项来提供静态文件前缀服务;

  3、在导入静态文件时用 {{static_url('XX.css')}} 方式实现主动缓存静态文件

Tornado中, 你可以通过在应用程序中指定特殊的 static_path 来提供静态文 件服务:

settings = {
    "static_path": os.path.join(os.path.dirname(__file__), "static"),
    "cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
    "login_url": "/login",
    "xsrf_cookies": True,
}
application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/login", LoginHandler),
    (r"/(apple-touch-icon\.png)", tornado.web.StaticFileHandler,
     dict(path=settings['static_path'])),
], **settings)
View Code

相关文章:

  • 2021-11-19
  • 2021-08-25
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-06-24
  • 2022-12-23
猜你喜欢
  • 2021-11-06
  • 2021-07-18
  • 2021-09-29
  • 2022-12-23
  • 2021-08-26
  • 2021-07-20
相关资源
相似解决方案