python - Django HTML 模板缓存

标签 python django django-templates django-views

我对 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/

相关文章:

Python : How can I access Lotus Notes 8. 5 收件箱阅读邮件

python - tzlocal 为我提供 UTC 作为我的本地时区

django - 如何在 javascript 中引用 django 变量?

python - 属性错误 : 'list' object has no attribute 'copy'

Python正则exp匹配上标2

python - 占用空间最小的 Python? CPython?

python - 如何使 html div 元素跟随垂直滚动(在 html/django 中)?

django - 如何在 Django 中正确处理中止的 HTTP 请求

Django NoReverseMatch

Django 模板引擎缩进