Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Django HTMX CSRF setup
<script src="{% static 'app.js' %}" data-csrftoken="{{ csrf_token }}"></script>
const csrfToken = document.currentScript.dataset.csrftoken;
htmx.on('htmx:configRequest', (event) => {
if (csrfToken) {
evt.detail.headers['x-csrftoken'] = csrfToken;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment