File: installation.rst

package info (click to toggle)
django-htmx 1.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: javascript: 3,395; python: 956; makefile: 27; sh: 19
file content (62 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Installation
============

Requirements
------------

Python 3.9 to 3.13 supported.

Django 4.2 to 5.2 supported.

Installation
------------

1. Install with **pip**:

   .. code-block:: sh

       python -m pip install django-htmx

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

   .. code-block:: python

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

3. (Optional) Add the middleware:

   .. code-block:: python

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

   The middleware adds ``request.htmx``, as described in :doc:`middleware`.

4. (Optional) Update your base template to:

   1. Add htmx and the django-htmx extension script to your pages with a :doc:`template tag <template_tags>`, available for Django templates and Jinja2.
   2. Add Django’s CSRF token to all htmx requests, so POST requests work, per :ref:`this tip <tips-csrf-token>`.

   In the typical case, with Django templates:

   .. code-block:: django
      :emphasize-lines: 1,6,8

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