Skip to content

Instantly share code, notes, and snippets.

@janaSunrise
Created July 28, 2021 15:49
Show Gist options
  • Save janaSunrise/6b21414edbe2fb50489364e92a51b3ce to your computer and use it in GitHub Desktop.
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.
// 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