我对 Django 的经验有限,但我遇到了一个问题,我更新了在我们的页面上提供重要 View 的 HTML 模板文件,而某些用户在查看页面时没有获得更新的 View 。几乎就像他们的设备正在缓存页面一样。现在这个页面不是静态的,而是根据请求动态生成的。现在我要改变的部分是嵌入的java脚本。
我的问题是有没有一种方法可以缓存页面的一部分,而其他部分则不是来自同一模板?
最佳答案
您可以使用 {% cache %}
缓存模板的片段。模板标签:
{% load cache %} <-- at the top of the template
{% cache 500 sidebar %}
.. sidebar ..
{% endcache %}
It takes at least two arguments: the cache timeout, in seconds, and the name to give the cache fragment.
关于python - Django HTML 模板缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163981/