[英]How do i cache bust with Django's staticfiles?
I have a webpage which includes an image. 我有一个包含图片的网页。 I wish to cache bust that image using the ?
我想使用?缓存该图像吗? technique.
技术。 However, staticfiles encodes questionmarks as '%3F', so the path is no longer correct.
但是,静态文件将问号编码为'%3F',因此路径不再正确。
{% load staticfiles %}
<img src="{% static 'poll/img/test.jpg?v2' %}">
Gets compiled as. 获取编译为。
<img src="/static/poll/img/test.jpg%3Fv2">
There is no test.jpg%3Fv2
file. 没有
test.jpg%3Fv2
文件。 So it doesn't show. 因此它不会显示。 Using
static
it works fine. 使用
static
可以正常工作。
{% load static %}
<img src="{% static 'poll/img/test.jpg?v2' %}">
Get's compiled as expected. 获取按预期方式进行编译。 I want to use
staticfiles
rather than static
as I serve my static files from a cloud service. 我想使用
staticfiles
而不是static
因为我从云服务提供静态文件。 Is there a way to prevent the encoding of my string path or a workaround of the problem? 有没有办法防止我的字符串路径编码或问题的解决方法?
To solve the encoding either write your own version of the static tag or simply move the parameters beyond the tag. 要解决编码问题,请编写您自己的静态标签版本,或者将参数移到标签之外。
{% load staticfiles %}
<img src="{% static 'poll/img/test.jpg' %}?v2">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.