我正在寻找一种在使用 Django (Django 2+; Python 3.5+) 模板缓存时从特定模板文件中列出缓存键的方法。例如:
{% load cache %}
{% block header %}
{% cache 600 contact_page_header %}
Contact page header, this will create a cache file.
{% endcache %}
{% endblock header %}
{% block content %}
<!-- HTML stuff here -->
{% cache 600 contact_page_content %} {# Fragment #}
Contact page header, this will create a cache file.
{% endcache %}
<!-- More HTML stuff -->
{% endblock content %}
Run Code Online (Sandbox Code Playgroud)
在这里,有contact_page_header和contact_page_content。这两个都有自己的.djcache …