Python 禁用web.py web服务器中的缓存,忽略HTTP头
我有一个python的web应用程序,web服务器是用library web.py实现的 但是,当浏览器在web服务器上发送请求时,例如在/static/index.html上,它会在http头中包含“IF-MATCH-NONE”和“IF-MODIFIED-SINCE”字段,并且服务器会检查html页面请求是否自上次以来已被修改(以及http 304-未修改的服务器响应) 在任何情况下,我如何强制html页面响应,即使它没有被修改 web服务器的代码如下所示Python 禁用web.py web服务器中的缓存,忽略HTTP头,python,http,caching,web.py,http-status-code-304,Python,Http,Caching,Web.py,Http Status Code 304,我有一个python的web应用程序,web服务器是用library web.py实现的 但是,当浏览器在web服务器上发送请求时,例如在/static/index.html上,它会在http头中包含“IF-MATCH-NONE”和“IF-MODIFIED-SINCE”字段,并且服务器会检查html页面请求是否自上次以来已被修改(以及http 304-未修改的服务器响应) 在任何情况下,我如何强制html页面响应,即使它没有被修改 web服务器的代码如下所示 import web urls=
import web
urls= (
'/', 'redirect',
'/static/*','index2',
'/home/','process'
)
app=web.application(urls,globals())
class redirect:
def GET(self):
..
return web.redirect("/static/index.html")
def POST(self):
..
raise web.seeother("/static/index.html")
class index2:
def GET(self):
...
some checks
....
if __name__=="__main__":
app.run()
您需要在响应头中添加
缓存控制字段:
web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")
例如:
import web
urls = ("/.*", "hello")
app = web.application(urls, globals())
class hello(object):
def GET(self):
web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")
return "Hello, world!"
if __name__ == "__main__":
app.run()
作为权宜之计,您可以将流行的web浏览器配置为在“开发人员控制台”打开时禁用缓存。这对我来说已经足够了。