Skip to content
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

wagtail-cache and async fetch #81

Open
davidu1975 opened this issue Nov 6, 2024 · 1 comment
Open

wagtail-cache and async fetch #81

davidu1975 opened this issue Nov 6, 2024 · 1 comment

Comments

@davidu1975
Copy link

davidu1975 commented Nov 6, 2024

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)
})

@vsalvino
Copy link
Contributor

vsalvino commented Nov 6, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants