Skip to main content

Use lucide in your Django and Jinja templates.

Project description

dj-lucide

CI pypi black pre-commit

Use lucide icons in your Django and Jinja templates.

Requirements

Python 3.8 to 3.13 supported.

Django 3.2 to 5.2 supported.

Usage

The dj-lucide package supports both Django templates and Jinja templates. Follow the appropriate guide below.

Django templates

  1. Install with python -m pip install dj-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") }}

Use the Latest Lucide Icons (Custom Update & ZIP Selection)

By default, this package uses the Lucide icon ZIP file bundled within the package. You can now easily update to the latest Lucide icons at any time—without waiting for a package release.

Updating to the Latest Icons

A management command is provided to fetch the newest icons and save them to your project’s root folder.

Usage:

python manage.py update_lucide_icons

This will download the latest Lucide icon ZIP from GitHub and save it as lucide-latest.zip in your Django project’s root directory.

Using a Custom ZIP File (Settings Option)

You can explicitly tell lucide which ZIP file to use by setting the following variable in your settings.py:

import os
LUCIDE_ICONS_ZIP_PATH = os.path.join(BASE_DIR, "lucide-latest.zip")

If this setting is provided and the file exists, lucide will always load icons from your specified ZIP file.

If the file is missing or the setting is unset, lucide falls back to the built-in package ZIP.

Acknowledgements

This package is heavely inspired by Adam Johnson's heroicons. It's actually mostly copied from it so a huge thanks Adam! This package is forked from Francisco Macedo's lucide.

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_lucide-1.1.12.tar.gz (419.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_lucide-1.1.12-py3-none-any.whl (419.7 kB view details)

Uploaded Python 3

File details

Details for the file dj_lucide-1.1.12.tar.gz.

File metadata

  • Download URL: dj_lucide-1.1.12.tar.gz
  • Upload date:
  • Size: 419.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_lucide-1.1.12.tar.gz
Algorithm Hash digest
SHA256 8581a7e2f7bf8a080223f3164d645aced5eb2e1640dff5edec56d93285c01f9a
MD5 2824e7639d2c18ddd83bafd4c7279a7f
BLAKE2b-256 be75d908527e150b12ebe509a7074b27e1eafad5937baa5b6440e2cc68aa350f

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_lucide-1.1.12.tar.gz:

Publisher: main.yml on vidski/dj-lucide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dj_lucide-1.1.12-py3-none-any.whl.

File metadata

  • Download URL: dj_lucide-1.1.12-py3-none-any.whl
  • Upload date:
  • Size: 419.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_lucide-1.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 30c5fd522205c906ae46a341874cd50879f38ceadbb69c88907e4d483532a7d0
MD5 d735f5b8369bb6d9927f1f21cd950483
BLAKE2b-256 0fbc2052b774a1923668c4e1d44f27dc77a5a9559a317f4b08fcf8b26dbbc9af

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_lucide-1.1.12-py3-none-any.whl:

Publisher: main.yml on vidski/dj-lucide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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