Python 缓存控制仅适用于媒体文件,而不适用于在django中使用django管道服务的静态文件
我正在尝试对静态文件使用缓存控制。以下是我的Python 缓存控制仅适用于媒体文件,而不适用于在django中使用django管道服务的静态文件,python,django,.htaccess,cache-control,Python,Django,.htaccess,Cache Control,我正在尝试对静态文件使用缓存控制。以下是我的.htaccess文件代码 # 1 YEAR <FilesMatch "\.(ico|svg|woff|eot|ttf)$"> Header set Cache-Control "max-age=31536000, public" </FilesMatch> # 1 WEEK <FilesMatch "\.(jpg|png|gif|css|js)$"> Header set Cache-Control "max-a
.htaccess
文件代码
# 1 YEAR
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
使用redbot.org测试媒体文件URL时会出现如下情况
HTTP/1.1 200 OK
Date: Sat, 13 Sep 2014 08:46:35 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Wed, 10 Sep 2014 17:57:24 GMT
ETag: "4b6d-502b9c8c3966e"
Accept-Ranges: bytes
Content-Length: 19309
Cache-Control: max-age=604800, public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg
对于静态文件,这是它的输出
HTTP/1.1 200 OK
Date: Sat, 13 Sep 2014 08:49:12 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
ETag: 1409031812.69
Content-Length: 23907
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/png
知道我遗漏了什么吗?您正在从django(通过django管道)但从web服务器提供静态文件。那么.htaccess指令就没有效果了 看起来您是从django(通过django管道)而不是从web服务器提供静态文件。那么.htaccess指令就没有效果了。不是吗?你说得对。我通过Django提供静态文件,而媒体文件使用Apache。从apache提供静态文件解决了这个问题。Ok。我会把它贴成anwer。
HTTP/1.1 200 OK
Date: Sat, 13 Sep 2014 08:49:12 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
ETag: 1409031812.69
Content-Length: 23907
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/png