SVG template tag for Django
Project description
dj-svg
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dj_svg-0.3.1.tar.gz
.
File metadata
- Download URL: dj_svg-0.3.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36fa307cf6e22c20f92cd3a2b232cfc4291b844e9647e47b6f4ca847f08c0de4 |
|
MD5 | 5ebfc575b3909e79386d7e11683ac6d7 |
|
BLAKE2b-256 | d6f1175e7b7c302127bad00591e58690e3b9930556cdc9f5503ec07082e17c67 |
File details
Details for the file dj_svg-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: dj_svg-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554e6a0c40684d73c1b997bc2ed64aaff3d3f0108165a0da95b7290c3d74ab4a |
|
MD5 | 7860af570808f957d17fec639cec0f1a |
|
BLAKE2b-256 | 01c03c676631a4d8f276ddf92e27f317839fe9a804671c517c18b5c4e273638b |