djangosnippets.org: Latest snippets tagged with 'fragment'http://djangosnippets.org/tags/fragment/2012-03-24T12:58:31.546817-05:00Delete template fragment cache
2012-03-24T12:58:31.546817-05:00DeRomanokhttp://djangosnippets.org/snippets/2723/<p>Template:</p>
<p>{% load cache %}
{% cache 1800 posts blog.pk %}
{# Show posts #}
{% endcache %}</p>
<p>Code:</p>
<p>def view(request, pk):
# Code
blog = get_object_or_404(Blog, pk=pk)
delete_template_fragment_cache('posts', blog.pk)
# Code</p>
Freely redistributableTemplate tag to clear cached template fragment
2009-11-16T15:34:39.877563-06:00joao.coelhohttp://djangosnippets.org/snippets/1801/<p>This is a custom template tag that clears the cache that was created with the <strong>cache</strong> tag.</p>
<pre><code>{% load clearcache %}
{% clearcache [fragment_name] [var1] [var2] .. %}
</code></pre>
<p>Create <strong>app/templatetags</strong> folder with <strong><em><em>init</em></em>.py</strong> and copy code into <strong>clearcache.py</strong> file.</p>
<pre><code>polls/
templatetags/
__init__.py
clearcache.py
</code></pre>
<p>Based on django.templatetags.cache. See Django docs …</p>
Freely redistributable