Disable Jinja template caching for certain filter

前端 未结 4 1850
长情又很酷
长情又很酷 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:19

    There is a way to disable caching of the result of a particular filter: it's by not using a constant input, e.g. by exposing a random source as a global variable.

    # Expose to Jinja
    from random import random as RANDOM
    

    And in the templates

    {{ RANDOM() | eval_this_filter_every_time }}
    

提交回复
热议问题