Disable Jinja template caching for certain filter

前端 未结 4 1845
长情又很酷
长情又很酷 2020-12-19 14:10

We have a custom Jinja filter that we use for creating cache busting URL for our Javascript and CSS resources. We now noticed that in our production environment the final, c

4条回答
  •  借酒劲吻你
    2020-12-19 14:21

    The easiest way to do this is:

    On your flask server script do this:

    from time import ctime
    

    In your app.route() function,

    in the return line add:

    time=ctime()
    

    for example:

    return render_template('signup', error = error, time = ctime())
    

    In the html reference for your css file(if using jinja2) add:

    ?{{time}}
    

    at the end of your reference line.

    That shoud look like this:

    
    

    Worked pretty good for me and the browser stopped caching.

    I hope it helps!

    Cheers!

    -Nelio

提交回复
热议问题