Skip to main content

Use lucide in your Django and Jinja templates.

Project description

lucide

Lucide - Beautiful & consistent icon toolkit made by the community. Open-source project and a fork of Feather Icons.

CI pypi black pre-commit

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

  1. Install with python -m pip install lucide[django].

  2. Add to your INSTALLED_APPS:

    INSTALLED_APPS = [
        ...,
        "lucide",
        ...,
    ]
    
  3. 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 be None, 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

  1. Install with python -m pip install lucide[jinja].

  2. Adjust your Jinja Environment to add the global lucide function from lucide.jinja. For example:

        from lucide.jinja import lucide
        from jinja2 import Environment
    
        env = Environment()
        env.globals.update({
                "lucide": lucide
            }
        )
    
  3. 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 be None, 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

lucide-1.1.2.tar.gz (385.3 kB view details)

Uploaded Source

Built Distribution

lucide-1.1.2-py3-none-any.whl (382.9 kB view details)

Uploaded Python 3

File details

Details for the file lucide-1.1.2.tar.gz.

File metadata

  • Download URL: lucide-1.1.2.tar.gz
  • Upload date:
  • Size: 385.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for lucide-1.1.2.tar.gz
Algorithm Hash digest
SHA256 a7de5f8294f303fe41d5f171f76310fa030eda885fd54643459061715d101b84
MD5 694587524f87d694e33ee1119d6df551
BLAKE2b-256 e896cc4a024737f7f59cf1391f4c253587d7cfe71a074763719b64832b984522

See more details on using hashes here.

File details

Details for the file lucide-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: lucide-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 382.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for lucide-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07951253f9b79c1ae6c2a8d0b05d43ba653a1e954e0395b70b8cae63b9c40014
MD5 69b950fb3004c15721ee75c343a7cf06
BLAKE2b-256 01f758bb745969cb5af37982d8e4ce338fe85eaeb0749b46bbab4199b2d5330a

See more details on using hashes here.

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