Zombie SharedDataMiddleware in Python Heroku

I am creating a Flask application on Heroku. Everything worked fine until I added static files. I use this:

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

When you deploy the application for the first time, the corresponding files in. / static will be available at herokuapp.com/static. But after this initial deployment, the files never change on Heroku. If I changed the last line to:

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

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

It seems that the file mirror is stuck in the system. I changed it four times and can still access all the urls.

+6
source share
1 answer

SharedDataMiddleware by default sends HTTP headers Cache-Control and Expires , which means that your web browser may not even send a request to the server and just use old cache files. 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 :

 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = None 
+4
source

Source: https://habr.com/ru/post/920649/


All Articles