Python Heroku上的僵尸SharedDataMiddleware [英] Zombie SharedDataMiddleware on Python Heroku

查看:263
本文介绍了Python Heroku上的僵尸SharedDataMiddleware的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Heroku上设置一个Flask应用程序。一切工作正常,直到我添加静态文件。我使用这个:

 来自werkzeug import SharedDataMiddleware 
app = Flask(__ name__)
app。 wsgi_app = SharedDataMiddleware(app.wsgi_app,{'/ static':os.path.join(os.path.dirname(__ file__),'static')})

第一次部署应用程序时,./static中的相应文件将在herokuapp.com/static上提供。但在初始部署之后,Heroku上的文件永远不会改变。如果我将最后一行更改为:

  app.wsgi_app = SharedDataMiddleware(app.wsgi_app,{'/ assets':os。 path.join(os.path.dirname(__ file__),'static')})

静态文件的URL,herokuapp.com/assets,然后我可以看到更新的文件。



这似乎是文件的一面镜子卡在系统中。我已经改变了它四次,并且仍然可以访问所有的URL。 SharedDataMiddleware默认发送 Cache-Control Expires HTTP标头,这意味着您的Web浏览器可能甚至不会向服务器发送请求,只是使用旧文件来自缓存。尝试禁用缓存

  app.wsgi_app = SharedDataMiddleware(
app.wsgi_app,
{'/ static':os.path.join(os.path.dirname(__ file__),'static ')},
cache = False)

Flask和静态文件一样。 禁用

  app.config ['SEND_FILE_MAX_AGE_DEFAULT'] =无


I'm setting up a Flask app on Heroku. Everything is working fine until I added static files. I'm using this:

from werkzeug import SharedDataMiddleware
app = Flask(__name__)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/static': os.path.join(os.path.dirname(__file__), 'static') })

The first time I deploy the app, the appropriate files in the ./static will be available at herokuapp.com/static. But after that initial deploy, the files never change on Heroku. If I change the last line to:

app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/assets': os.path.join(os.path.dirname(__file__), 'static') })

a new URL for the static files, herokuapp.com/assets, then I can see the updated files.

It seems like a mirror of the files gets stuck in the system. I've changed it four times and can access all of the URLs still.

解决方案

SharedDataMiddleware defaults to sending Cache-Control and Expires HTTP headers, which means that your web browser may not even send a request to the server and just use the old files from cache. Try disabling the cache:

app.wsgi_app = SharedDataMiddleware(
    app.wsgi_app,
    {'/static': os.path.join(os.path.dirname(__file__), 'static')},
    cache=False)

Flask does the same with static files. To disable it there:

app.config['SEND_FILE_MAX_AGE_DEFAULT'] = None

这篇关于Python Heroku上的僵尸SharedDataMiddleware的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆