我有一个 python 网络应用程序,网络服务器是用库 web.py 实现的。
但是,当浏览器向 Web 服务器发送请求时,例如/static/index.html,它在 http header 中包含字段“IF-MATCH-NONE”和“IF-MODIFIED-SINCE”以及服务器检查 html 页面请求自上次以来是否已被修改(以及服务器响应 http 304 - 未修改)...
如何在任何情况下强制响应 html 页面,即使它没有被修改?
Web 服务器的代码如下。
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()
最佳答案
需要在响应头中添加Cache-Control
字段:
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()
关于python - 在 web.py web 服务器中禁用缓存,忽略 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36910952/