在开发环境里,静态文件需要经常改动,特别是css,可以用下面方式禁用缓存。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import tornado.web
class NoCacheStaticFileHandler(tornado.web.StaticFileHandler):
def set_extra_headers(self, path):
self.set_header("Cache-control", "no-cache")
class Application(tornado.web.Application):
def __init__(self):
handlers = [
# ...
url(r"/static/(.*)",
tornado.web.StaticFileHandler if not options.debug else NoCacheStaticFileHandler, {
"path": '/var/www/static'
}, name="static")
下面是我实际中使用的:
1
2
3
4
handlers = [
# (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': settings['static_path']})
(r'/static/(.*)', NoCacheStaticFileHandler, {'path': settings['static_path']})
]
其实最简单的方式:
1
2
3
4
5
6
7
8
settings = dict(
static_path=os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies=True,
cookie_secret=setting.COOKIE_SECRET,
autoescape=None,
login_url='/oauth/sign-in',
debug=True, # here
)
本文网址: https://pylist.com/topic/124.html 转摘请注明来源