Django CSRF check failing with an Ajax POST request

前端 未结 22 1874
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 03:46

I could use some help complying with Django\'s CSRF protection mechanism via my AJAX post. I\'ve followed the directions here:

http://docs.djangoproject.com/en/dev/r

22条回答
  •  清歌不尽
    2020-11-22 03:57

    If someone is strugling with axios to make this work this helped me:

    import axios from 'axios';
    
    axios.defaults.xsrfCookieName = 'csrftoken'
    axios.defaults.xsrfHeaderName = 'X-CSRFToken'
    

    Source: https://cbuelter.wordpress.com/2017/04/10/django-csrf-with-axios/

提交回复
热议问题