A simple way to use Javascript importmaps
in your Django projects.
Use Javascript libraries in your Django projects without having to install node
and related frontend tooling like webpack
, etc.
No frontend build system required!
- Install from pypi
uv add lfp-importmap
or
python -m pip install lfp-importmap
- Add
lfp_importmap
to yourINSTALLED_APPS
in yoursettings.py
INSTALLED_APPS = [
...
'lfp_importmap',
]
- Add any JS library using the new management command:
python manage.py importmap add htmx.org
This will create an importmap.config.json
file in your project root.
It will also vendor the package code and make it available in your templates.
- In your
base.html
template, add the following:
{% load lfp_importmap %}
<html>
<head>
... {% javascript_importmap_tags %}
</head>
<body>
...
</body>
</html>
- That's it! The module is now ready for use in your templates.
Continuing the example from above, you can now use the htmx
module in your templates:
<button hx-get="{% url 'my-url-name' %}">Click me</button>
MIT