Home Ask Login Register

Developers Planet

Your answer is one click away!

NJP February 2016

Django static templatetag not displaying SVG

I'm trying to use django's static templatetag to display an SVG, but it doesn't seem to recognize the SVG as a valid image url. This is what I currently have:

settings.py

import mimetypes
mimetypes.add_type("images/svg+xml", ".svg", True)

landing.html

{% load staticfiles %}
<img src="{% static 'images/right-arrow.svg' %}" />

At least in my view.py, it recognizes the SVG mimetype:

views.py

print(mimetypes.guess_type(static('images/right-arrow.svg'))) 
  # returns ('images/svg+xml', None)

The SVG does display in a non-django page, and it will download the SVG if I try to open the SVG path in a new browser tab.

I'm currently using python 3.4 and django 1.8.4.

Answers


NJP February 2016

I found the issue. In settings.py, it should be mimetypes.add_type('image/svg+xml', '.svg', True). image should be singular.

Post Status

Asked in February 2016
Viewed 1,267 times
Voted 13
Answered 1 times

Search




Leave an answer


Quote of the day: live life