Skip to content
Back to top
View this page
Edit this page

# Installation

## Requirements

Python 3.10 to 3.14 supported.

Django 5.2 to 6.1 supported.

## Installation

1. Install with pip:

       python -m pip install django-htmx

2. Add django-htmx to your `INSTALLED_APPS`:

       INSTALLED_APPS = [
           ...,
           "django_htmx",
           ...,
       ]

3. (Optional) Add the middleware:

       MIDDLEWARE = [
           ...,
           "django_htmx.middleware.HtmxMiddleware",
           ...,
       ]

   The middleware adds `request.htmx`, as described in Middleware.

4. (Optional) Update your base template to:

   1. Add htmx and the django-htmx extension script to your pages with a template tag, available for Django templates and Jinja2.

   2. Add Django’s CSRF token to all htmx requests, so POST requests work, per this tip.

   In the typical case, with Django templates:

        {% load django_htmx %}
        <!doctype html>
        <html>
          <head>
            ...
            {% htmx_script %}
          </head>
          <body hx-headers='{"x-csrftoken": "{{ csrf_token }}"}'>
            ...
          </body>
        </html>

   Note

   For htmx version 4, use `hx-headers:inherited` instead of `hx-headers` on the `<body>` tag.