在Django中,我正在快速提供png图像:
from matplotlib.pyplot import figure
fig_ATF = figure(figsize=(5, 5), facecolor='white')
....
response = HttpResponse(content_type='image/png')
fig_ATF.savefig(response, format='png')
fig_ATF.clear()
response['Content-Length'] = len(response.content)
return response
Firefox正确地将 Content-Type 解释为 image / png 。但是,Chromium不显示图像并抱怨:资源被解释为图像但是使用MIME类型text / html传输
这些是Chromium中相关的响应标头:
Cache-Control:max-age=0
Connection:close
Content-Encoding:gzip
Content-Length:20
Content-Type:text/html; charset=utf-8
Date:Tue, 17 Mar 2015 10:08:36 GMT
Expires:Tue, 17 Mar 2015 10:08:37 GMT
Last-Modified:Tue, 17 Mar 2015 10:08:37 GMT
Server:Apache
Vary:Cookie,Accept-Encoding
X-Frame-Options:SAMEORIGIN
编辑直接访问时,图像在Chromium中加载得很好。这个问题似乎与它通过jQuery添加了ajax的事实有关:
$('#img_location').html('<img src="/path/to/image.png?' + Date.now() + '" width="500" height="500" />');
答案 0 :(得分:0)
通过在Apache的httpd.conf中添加以下行来解决这个问题:
AddType image/png .png