Problems updating the Django template cache

I tried to write a simple application in Django to cache some external images and display / update on demand.

What am I doing:
{% load cache %} {% cache 1500 image %} {% endcache %}

and update this in the view code when updating the "button":
key = "template.cache.image.d41d8cd98f00b204e9800998ecf8427e" cache.delete( key )

Now it works fine when the image is deleted or I replace src with a different value. It also works when I print something inside the tags {% cache ... %} {% endcache %}, but when the image changes - like I replace it with some other one - the refresh button does nothing with it until I refresh the entire page with the browser refresh button (or using F5) . I tested it on Chrome (some version) and Opera (11). My view does not use cache parameters, but I tried it with @never_cachesome other tags, and nothing helped.

I hope you can help me.


Regards.

: , , - . , python, , , ( , ), , "" python HttpResponse/render_to_response "html form", .

+3
3

.

django, -

    <img src="/image.jpg?cachebuster={{uuid}}" /> 

uuid .

, , , , . , .

+3

, ? , , django.

, . , ,

<img src="/image.jpg?cachebuster=blah23" />

+2

, .

. , , , -   . ! , , ! , , .

Ken Cochrane: - . ! -, timezone.now() URL-, : utc = 2018-02-19_22.57.30 ( URL-, , URL- - ).

: '% Y-% m-% d_% H.% M.% S'

, , , . : timezone.now() . , , . - , , .

, ? updated = 2018-02-19_22.57.30

The solution can be used while maintaining the same image name, but changing the image file using the timestamp of the image file system for the query string. Only when the image is changed will the timestamp be different and the browser will be updated. When the image file is the same, the timestamp will be the same, so the browser can display the cached version.

0
source

All Articles