Created
July 28, 2021 15:49
-
-
Save janaSunrise/6b21414edbe2fb50489364e92a51b3ce to your computer and use it in GitHub Desktop.
Easiest way to fix the error of `CSRF Failed` when building a fullstack App with Django and JS framework. This is an example to fix it with Axios library, when being used to make requests to backend. Since Django and DRF requires a CSRF token to verify in Session Authentication, When using Axios, this simple axios config fixes the error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fix CSRF error in django using this. | |
axios.defaults.xsrfCookieName = "csrftoken"; | |
axios.defaults.xsrfHeaderName = "X-CSRFToken"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment