Use justmyresource resource packs in your Django and Jinja templates
Project description
django-justmyresource
Use JustMyResource resource packs in your Django and Jinja templates.
Requirements
Python 3.10+ supported.
Django 4.2+ supported (for Django integration).
Jinja2 3.0+ supported (for Jinja integration).
Installation
Install with the appropriate extras:
# For Django templates
pip install django-justmyresource[django]
# For Jinja templates
pip install django-justmyresource[jinja]
# For both
pip install django-justmyresource[django,jinja]
You'll also need to install resource packs. For example, to use Lucide icons:
pip install justmyresource-lucide
Usage
Django Templates
- Add to your
INSTALLED_APPS:
INSTALLED_APPS = [
...,
"django_justmyresource",
...,
]
- Load the template library in your templates:
{% load justmyresource %}
Alternatively, make the library available in all templates by adding it to the builtins option:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
# ...
"OPTIONS": {
# ...
"builtins": [
...,
"django_justmyresource.templatetags.justmyresource",
...,
],
},
}
]
- Use the
icontag to render SVG icons:
{% icon "lucide:a-arrow-down" %}
The icon tag accepts these arguments:
name, positional: The resource name with optional prefix (e.g.,"lucide:home"or"justmyresource-lucide/lucide:home").size, keyword: An integer for width and height attributes. Defaults to24. Can beNoneto preserve original size.- Any number of keyword arguments: These are added as HTML attributes. Underscores are replaced with dashes (e.g.,
data_testbecomesdata-test).
Most attributes are added to the <svg> tag, but these are applied to <path> elements:
stroke-linecapstroke-linejoinvector-effect
Examples
Basic icon:
{% icon "lucide:a-arrow-down" %}
Custom size and CSS class:
{% icon "lucide:a-arrow-down" size=40 class="mr-4" %}
With data attributes and path-level attributes:
{% icon "lucide:a-arrow-down" stroke_width=1 data_controller="language" %}
Jinja Templates
- Add the
iconfunction to your Jinja environment:
from django_justmyresource.jinja import icon
from jinja2 import Environment
env = Environment()
env.globals.update({
"icon": icon,
})
- Use the
iconfunction in your templates:
{{ icon("lucide:a-arrow-down") }}
The function accepts the same arguments as the Django template tag:
name, positional: The resource name with optional prefix.size, keyword: Size for width and height. Defaults to24. Can beNone.- Any number of keyword arguments: HTML attributes (underscores become dashes).
Examples
Basic icon:
{{ icon("lucide:a-arrow-down") }}
Custom size and CSS class:
{{ icon("lucide:a-arrow-down", size=40, class="mr-4") }}
With data attributes:
{{ icon("lucide:a-arrow-down", stroke_width=1, data_controller="language") }}
Configuration
You can configure the JustMyResource registry via Django settings:
JUSTMYRESOURCE_DEFAULT_PREFIX
Set a default prefix for bare resource names (without a colon):
JUSTMYRESOURCE_DEFAULT_PREFIX = "lucide"
Then you can use bare names in templates:
{% icon "home" %} # Resolves to "lucide:home"
JUSTMYRESOURCE_BLOCKLIST
Exclude specific resource packs from discovery:
# As a list
JUSTMYRESOURCE_BLOCKLIST = ["pack1", "pack2"]
# Or as a comma-separated string
JUSTMYRESOURCE_BLOCKLIST = "pack1,pack2"
JUSTMYRESOURCE_PREFIX_MAP
Map custom aliases to qualified pack names:
# As a dict
JUSTMYRESOURCE_PREFIX_MAP = {
"icons": "justmyresource-lucide/lucide",
"fa": "justmyresource-font-awesome/font-awesome",
}
# Or as a comma-separated string
JUSTMYRESOURCE_PREFIX_MAP = "icons=justmyresource-lucide/lucide,fa=justmyresource-font-awesome/font-awesome"
Resource Name Resolution
Resource names can be specified in multiple formats:
- Qualified name:
"justmyresource-lucide/lucide:home"- Always unique, no ambiguity - Short pack name:
"lucide:home"- Works if the pack name is unique - Alias:
"luc:home"- If the pack defines aliases viaget_prefixes() - Bare name:
"home"- RequiresJUSTMYRESOURCE_DEFAULT_PREFIXto be set
See the JustMyResource documentation for more details on resource resolution.
Available Resource Packs
Check the JustMyResource Icons repository for available icon packs:
justmyresource-lucide- Lucide iconsjustmyresource-heroicons- Heroiconsjustmyresource-phosphor- Phosphor iconsjustmyresource-font-awesome- Font Awesomejustmyresource-material-icons- Material Iconsjustmyresource-mdi- Material Design Icons
Acknowledgements
This project was initially inspired by lucide, a Django/Jinja integration for Lucide icons. The lucide project itself is heavily inspired by Adam Johnson's heroicons, and much of the template tag implementation and SVG rendering logic follows similar patterns.
Special thanks to:
- Francisco Macedo for the lucide project, which served as the initial reference
- Adam Johnson for the heroicons project, which established the pattern for Django icon template tags
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_justmyresource-0.1.0.tar.gz.
File metadata
- Download URL: django_justmyresource-0.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90a72aed4d0e208bfe9c5c718369e58aabbed2477db5e64eb4ada0cea447dcaa
|
|
| MD5 |
44ed9329ab1adc12fc2faf830a3938d6
|
|
| BLAKE2b-256 |
49a17b564c2dbe5422032fde867b8d1f970c23207ffc1fd8d96489f5805e2567
|
File details
Details for the file django_justmyresource-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_justmyresource-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21116491aee8c5c0b16a05f9b87773fd321078d689240344844be89e9c0c800b
|
|
| MD5 |
2a93eed301856b82723d2fe79d2a4f55
|
|
| BLAKE2b-256 |
d8756b6195e2edf363ecf0d2d5bb2852932eb42dd95d0fcb5aef12629fe8c464
|