Django开发者服务器可以正确地提供SVG吗? [英] Can the Django dev server correctly serve SVG?

查看:527
本文介绍了Django开发者服务器可以正确地提供SVG吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方式提供svg地图:

I am trying to serve a svg map using:

<object data="map.svg" type="image/svg+xml" width="400" height="300">
    <embed src="map.svg" type="image/svg+xml" width="400" height="300" />
</object>

在Firefox中,会导致插件提示。如果我重命名地图。 svg 映射。 xml 它正确显示图像。我假设这是因为Django的dev服务器(具体来说, django.views.static.serve )不是使用正确的mime类型来服务于svg。这是问题,如果是,是否有补丁?

In Firefox this leads to a plugin prompt. If I rename map.svg to map.xml it shows the image correctly. I assume this is because the Django's dev server (specifically django.views.static.serve) is not serving the svg with the correct mime-type. Is this the problem, and if so, is there a patch?

推荐答案

我没有Django可以测试这个这一刻,但它看起来像静态服务器使用模拟库库来确定内容类型(特别是guess_type())。

I don't have Django available to test this at the moment but it looks like the static server uses the mimetypes library to determine the content type (specifically guess_type()).

有一点谷歌,我遇到了一个一些代码,你可能会抛出你的settings.py来添加对svg内容类型的支持:

With a little bit a Googling, I came across some code that you could probably throw in your settings.py to add support for the svg content type:

import mimetypes

mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)

还有这个 blog post ,但它提到了一个类似的问题。他指定MIME类型存储在/etc/mime.types中,并且缺少SVG,因为它不是官方的MIME类型。他可能是正确的,因为在 IANA

There's also this blog post specific to Pylons but it mentions a similar issue. He specifies that the MIME types are stored in "/etc/mime.types" and that SVG is missing because it's not an official MIME type. He may be right, since I can't find a MIME-type for SVG anywhere on the IANA.

这篇关于Django开发者服务器可以正确地提供SVG吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆