Snippet List
Template:
{% load cache %}
{% cache 1800 posts blog.pk %}
{# Show posts #}
{% endcache %}
Code:
def view(request, pk):
# Code
blog = get_object_or_404(Blog, pk=pk)
delete_template_fragment_cache('posts', blog.pk)
# Code
This is a custom template tag that clears the cache that was created with the **cache** tag.
{% load clearcache %}
{% clearcache [fragment_name] [var1] [var2] .. %}
Create **app/templatetags** folder with **__init__.py** and copy code into **clearcache.py** file.
polls/
templatetags/
__init__.py
clearcache.py
Based on django.templatetags.cache. See Django docs on [custom template tags](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/)
- template
- cache
- clear
- fragment
2 snippets posted so far.