Skip to main content

dj-svg

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.

Installation

Install it from pypi.

pip install dj-svg

Add dj_svg to your INSTALLED_APPS.

    INSTALLED_APPS = (
        ...
        'dj_svg',
        ...
    )

Usage

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

    my_app
    |-- 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.

    # settings.py

    SVG_DIRS=[
        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.

Support

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

License

MIT

Metadata

Release files for dj-svg 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-svg 0.3.1
File Size Uploaded Provenance Actions
dj_svg-0.3.1.tar.gz 4.8 kB Without provenance Details for dj_svg-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dj-svg 0.3.1
File Interpreter ABI Platform Actions
dj_svg-0.3.1-py3-none-any.whl Python 3 none any Details for dj_svg-0.3.1-py3-none-any.whl

Total release size: 9.9 kB

Release files / dj_svg-0.3.1.tar.gz

Download URL dj_svg-0.3.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
36fa307cf6e22c20f92cd3a2b232cfc4291b844e9647e47b6f4ca847f08c0de4
BLAKE2b-256 checksum
How to use checksums
d6f1175e7b7c302127bad00591e58690e3b9930556cdc9f5503ec07082e17c67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / dj_svg-0.3.1-py3-none-any.whl

Download URL dj_svg-0.3.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
554e6a0c40684d73c1b997bc2ed64aaff3d3f0108165a0da95b7290c3d74ab4a
BLAKE2b-256 checksum
How to use checksums
01c03c676631a4d8f276ddf92e27f317839fe9a804671c517c18b5c4e273638b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for dj-svg 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page