Use lucide in your Django and Jinja templates.
Project description
lucide
Use lucide icons in your Django and Jinja templates.
Requirements
Python 3.8 to 3.12 supported.
Django 3.2 to 5.0 supported.
Usage
The lucide
package supports both Django templates and Jinja templates.
Follow the appropriate guide below.
Django templates
-
Install with
python -m pip install lucide[django]
. -
Add to your
INSTALLED_APPS
:INSTALLED_APPS = [ ..., "lucide", ..., ]
-
Now your templates can load the template library with:
{% load lucide %}
Alternatively, make the library available in all templates by adding it to the builtins option:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
# ...
"OPTIONS": {
# ...
"builtins": [
...,
"lucide.templatetags.lucide",
...,
],
},
}
]
The library provides one tag (lucide
) to render SVG icons which can take these arguments:
-
name
, positional: the name of the icon to use. You can see the icon names on the lucide grid. -
size
, keyword: an integer that will be used for the width and height attributes of the output<svg>
tag. Defaults to the icons’ designed sizes,24
. It can also beNone
, in which case no width or height attributes will be output. -
Any number of keyword arguments. These will be added as attributes in the output HTML. Underscores in attribute names will be replaced with dashes, allowing you to define e.g.
data-
attributes.
Most attributes will be added to the <svg>
tag containing the icon, but these attributes will be attached to the inner <path>
tags instead:
stroke-linecap
stroke-linejoin
vector-effect
Note: unlike the SVG code you can copy from lucide grid, there is no default
class
.
Examples
An "a-arrow-down” icon:
{% lucide "a-arrow-down" %}
The same icon at 40x40 pixels, and a CSS class:
{% lucide "a-arrow-down" size=40 class="mr-4" %}
That icon again, but with the paths changed to a narrower stroke width, and a "data-controller" attribute declared:
{% lucide "a-arrow-down" stroke_width=1 data_controller="language" %}
Jinja templates
-
Install with
python -m pip install lucide[jinja]
. -
Adjust your Jinja
Environment
to add the globallucide
function fromlucide.jinja
. For example:from lucide.jinja import lucide from jinja2 import Environment env = Environment() env.globals.update({ "lucide": lucide } )
-
Now in your templates you can call that function, which will render the corresponding
<svg>
icons. The function takes these arguments:
-
name
, positional: the name of the icon to use. You can see the icon names on the lucide grid -
size
, keyword: an integer that will be used for the width and height attributes of the output<svg>
tag. Defaults to the icons’ designed sizes,24
. Can beNone
, in which case no width or height attributes will be output. -
Any number of keyword arguments. These will be added as HTML attributes to the output HTML. Underscores in attribute names will be replaced with dashes, allowing you to define e.g.
data-
attributes.
Most attributes will be added to the <svg>
tag containing the icon, but these attributes will be attached to the inner <path>
tags instead:
stroke-linecap
stroke-linejoin
vector-effect
Note: unlike the SVG code you can copy from lucide grid, there is no default
class
.
Examples
An "a-arrow-down” icon:
{{ lucide("a-arrow-down") }}
The same icon at 40x40 pixels and a CSS class:
{{ lucide("a-arrow-down", size=40, class="mr-4") }}
That icon again, but with the paths changed to a narrower stroke width, and a "data-controller" attribute declared:
{{ lucide("a-arrow-down", stroke_width=1, data_controller="language") }}
Acknowledgements
This package is heavely inspired by Adam Johnson's heroicons. It's actually mostly copied from it so a huge thanks Adam!
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
Built Distribution
File details
Details for the file lucide-1.1.3.tar.gz
.
File metadata
- Download URL: lucide-1.1.3.tar.gz
- Upload date:
- Size: 385.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a931b627bc30a529c7f4e57d7b4c2d7379a86a75a4156eb4ced411aa66c1202f |
|
MD5 | ed313e03326af3006be293a5655e5c95 |
|
BLAKE2b-256 | d318466c33b2ebbb63f74496abad1038452bc46b6050decdb2110681c2de5a16 |
Provenance
The following attestation bundles were made for lucide-1.1.3.tar.gz
:
Publisher:
main.yml
on franciscobmacedo/lucide
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lucide-1.1.3.tar.gz
- Subject digest:
a931b627bc30a529c7f4e57d7b4c2d7379a86a75a4156eb4ced411aa66c1202f
- Sigstore transparency entry: 147563076
- Sigstore integration time:
- Predicate type:
File details
Details for the file lucide-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: lucide-1.1.3-py3-none-any.whl
- Upload date:
- Size: 383.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37c9cd5ac3914577b933896dcc4160631aa63a078b7b0a1cf19e984a93e78234 |
|
MD5 | 4d38a30bd483b77107eed96c535130db |
|
BLAKE2b-256 | a6778ac5fda43469c96630dd81817df7362c72cff671f93950a780ad3b13e7e9 |
Provenance
The following attestation bundles were made for lucide-1.1.3-py3-none-any.whl
:
Publisher:
main.yml
on franciscobmacedo/lucide
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lucide-1.1.3-py3-none-any.whl
- Subject digest:
37c9cd5ac3914577b933896dcc4160631aa63a078b7b0a1cf19e984a93e78234
- Sigstore transparency entry: 147563078
- Sigstore integration time:
- Predicate type: