2016-04-28 87 views
2

我在python中有一個web應用程序,web服務器是通過庫web.py來實現的。在web.py web服務器中禁用緩存,忽略HTTP標頭

但是,當瀏覽器在Web服務器發送請求時,例如在/static/index.html上,它在http標題中包含字段'IF-MATCH-NONE'和'IF-MODIFIED-SINCE'並且服務器檢查自上次以來是否修改了html頁面請求(以及服務器對http 304的響應 - 未修改)...

如何在任何情況下強制響應html頁面,即使它沒有被修改?

網絡服務器的代碼如下。

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() 
+0

作爲權宜之計,您可以配置流行的瀏覽器禁用緩存而「開發者控制檯「已打開。這對我來說已經足夠了。 – Gerard

回答

0

您需要添加響應頭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()