coderedcorp/wagtail-cache

wagtail-cache and async fetch

Opened this issue · 1 comments

We are getting "Invalid csrf token" when we have some javascript in our django templates in our wagtail project

does an async fetch POST cause issues with wagtail caching and csrf tokens ie

return await fetch(${submitAPIEndpoint}?js_enabled=True, {
method: 'POST',
headers: {
'Content-Type': "application/json",
'X-CSRFToken': csrfToken
},
body: JSON.stringify(body)
})

Question: do you have a valid CSRF token on the page? I'd recommend setting it in a script tag using the Django template as so:

<script>
csrfToken = "{% csrf_token %}";
</script>