-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add X-CSRFToken via htmx:configRequest event #196
Comments
There's no need for any Javascript. You can use django-htmx/example/example/templates/csrf-demo.html Lines 4 to 22 in 2c1f95b
I'm further adding a docs page in the Docs PR: https://github.com/adamchainz/django-htmx/pull/194/files#diff-3d3c9ddabd7ba7f0fa458351d17598c03548245af53febc5c09fd829bb42dea1 |
Oh yes I knew that :) But having to add that to each html tag where you want to do htmx requests "gets tedious". I started using hx-headers initially but kept on forgetting them, which is why I turned to the configRequest event - to remove friction :) Anyway, I'll consider this as out-of-scope for django-htmx :) |
Okay, my bad, I somehow totally missed the |
Description
I wanted to hear if there is any interest in adding the X-CSRFToken to every HTMX request by grabbing the
htmx:configRequest
event?I've had quite a good success by including the following in my base templates:
Including this in django-htmx by either modifying django-htmx.js (and removing the non-debug guard in jinja.py) could be one way of doing it. Another could be a seperate
{% htmx_csrf_header %}
template tag.Any thoughts?
The text was updated successfully, but these errors were encountered: