mako模板前端解决X-CSRFToken

在script标签中加上如下:

axios.interceptors.request.use(config => {
    config.headers['X-Requested-With'] = 'XMLHttpRequest';
    let regex = /^csrftoken=([^;.]*).*$/;
    let cookies = document.cookie.split('; ')
    let cookiesFilters = cookies.filter(v => {
    if(v.match(regex)) {
        return v
        }
    })
    config.headers['X-CSRFToken'] = cookiesFilters[0].split('=')[1]
    return config})

你可能感兴趣的:(mako模板前端解决X-CSRFToken)