This commit is contained in:
Ross
2025-12-05 13:56:12 +00:00
parent c71c229ea8
commit 1f155f0d56
4 changed files with 50 additions and 0 deletions
+25
View File
@@ -119,4 +119,29 @@
}
})();
</script>
<script>
// Ensure HTMX requests include Django CSRF token (reads from cookie)
(function(){
function getCookie(name){
let cookieValue = null;
if (document.cookie && document.cookie !== ''){
const cookies = document.cookie.split(';');
for (let i=0;i<cookies.length;i++){
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')){
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
document.body.addEventListener('htmx:configRequest', function(evt){
const csrftoken = getCookie('csrftoken');
if (csrftoken){
evt.detail.headers['X-CSRFToken'] = csrftoken;
}
});
})();
</script>
</html>
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

+25
View File
@@ -119,4 +119,29 @@
}
})();
</script>
<script>
// Ensure HTMX requests include Django CSRF token (reads from cookie)
(function(){
function getCookie(name){
let cookieValue = null;
if (document.cookie && document.cookie !== ''){
const cookies = document.cookie.split(';');
for (let i=0;i<cookies.length;i++){
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')){
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
document.body.addEventListener('htmx:configRequest', function(evt){
const csrftoken = getCookie('csrftoken');
if (csrftoken){
evt.detail.headers['X-CSRFToken'] = csrftoken;
}
});
})();
</script>
</html>