Can the Django dev server correctly serve SVG?

后端 未结 3 854
夕颜
夕颜 2020-12-01 05:32

I am trying to serve a svg map using:


    

        
      
      
      
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 06:14

    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()).

    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)
    

    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.

提交回复
热议问题