2👍
let csrftoken = Vue.$cookies.get('vcubes')
return axios.post('', data, {
headers: {
'X-CSRFToken': csrftoken
}
}).then(response => {
return response.data
})
This is pretty similar to Shane’s answer, but show’s how to get the csrf token in Vue. If your problem is getting the cookie, then this SO answer should help you.
1👍
Here’s what I use in django:
result = { "insert your key values here" }
data = JSON.stringify(result)
axios.post("{% url 'error_checking' %}", data, {headers: {'X-CSRFToken': '{{ csrf_token }}',}})
- [Django]-Getting Multiple Objects using Django rest_framework RetrieveAPIView
- [Django]-Django redirect() with additional parameters
- [Django]-Django Indexes with Model Inheritance
- [Django]-"Last" tag not working
- [Django]-Adding Google Map Markers with DJango Template Tags in Javascript
Source:stackexchange.com