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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With