将下面代码添加到base.html的script标签的全局配置中
axios.interceptors.request.use(config => {
config.headers['X-Requested-With'] = 'XMLHttpRequest';
let CSRFTokenLi = document.cookie.split('; ').find(v => v.match(/^csrftoken=([^;.]*).*$/))
config.headers['X-CSRFToken'] = CSRFTokenLi ? CSRFTokenLi.split('=')[1] : ''
return config
});
axios.interceptors.response.use(response => {
return response.data
})
网友评论