Skip to main content

SVG template tag for Django

Project description


PyPI version PyPI Supported Python Versions PyPI Supported Django Versions GitHub Actions (Code quality and tests)

dj-svg is a fork of django-inline-svg which works with Django >4, it's a simple plugin that adds an svg template tag to inline your SVGs in your Django templates.


Install it from pypi.

pip install dj-svg

Add dj_svg to your INSTALLED_APPS.



Store your SVGs in folder named svg at the root of any of your static file directories.

    |-- static
    |   |-- svg
    |       |-- logo.svg
    |       |-- check.svg
    |       |-- cross.svg

Use the svg template tag.

    {% load svg %}

    <h1 class="logo">{% svg 'logo' class="css-class" height="16" width="16" %}</h1>

You can set SVG_DIRS to control where to look for your svgs.


        os.path.join(BASE_DIR, 'my-svgs')

Passing html attributes to svg templatetag

With inlining SVG's, it's helpful to give them class names so you can change the fill color using CSS. And if you're using a framework like tailwind, you can do it like so:

{% svg 'icon-search' class='h-10 mt-6' %}

This will add fixed height and top margin to SVG.

Thanks to Jure Cuhalev for this one.


The tests are run against Django 4.0 to 5.0.4 on Python 3.8 to 3.12.



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_svg-0.3.1.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

dj_svg-0.3.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page