Django Render SVG

Published 30 Jun, 2020


How to render Django static SVG files.

To display SVG in HTML file normally we place the SVG code inside the HTML file. And that works almost no issues. But in some cases you need to serve the SVG from Django. This is useful where you can change the SVG over static without modifying the HTML file. Also dynamic SVG rendering is possible with this approach.

To render SVG in Django, place that SVG in static folder. Once SVG file placed in in static folder you can use the static to point into that SVG.

And use img tag to display SVG in html file.

{% load static %}

<img src="{% static 'svgs/awesome.svg' %} />

This article published under development on django tags. Please support me by subscribing to my Newsletter. By subscribing you will not miss any future articles in this category.