Skip to content

SarthakJariwala/lfp-importmap

Repository files navigation

lfp-importmap

A simple way to use Javascript importmaps in your Django projects.

What can you do with it?

Use Javascript libraries in your Django projects without having to install node and related frontend tooling like webpack, etc. No frontend build system required!

How to use it?

  1. Install from pypi
uv add lfp-importmap

or

python -m pip install lfp-importmap
  1. Add lfp_importmap to your INSTALLED_APPS in your settings.py
INSTALLED_APPS = [
    ...
    'lfp_importmap',
]
  1. 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.

  1. In your base.html template, add the following:
{% load lfp_importmap %}

<html>
  <head>
    ... {% javascript_importmap_tags %}
  </head>
  <body>
    ...
  </body>
</html>
  1. 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>

LICENSE

MIT

About

Javascript Importmaps for Django

Resources

License

Stars

Watchers

Forks

Packages

No packages published