Fix CSRF for HTMX POST requests
This commit is contained in:
@@ -6,6 +6,14 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Kitchen{% endblock %}</title>
|
||||
<script src="{% static 'kitchen/htmx.min.js' %}"></script>
|
||||
{% csrf_token %}
|
||||
<script>
|
||||
// Add CSRF token to all HTMX requests
|
||||
document.addEventListener('htmx:configRequest', function(evt) {
|
||||
const token = document.querySelector('[name=csrfmiddlewaretoken]');
|
||||
if (token) evt.detail.headers['X-CSRFToken'] = token.value;
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
:root {
|
||||
--bg-dark: #15131c;
|
||||
|
||||
Reference in New Issue
Block a user