import cookie from 'react-cookies';
const csrfToken = cookie.load('csrftoken')
onSubmitSignUp = () => {
fetch('http://127.0.0.1:8000/register/', {
method: 'post',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
username: this.state.username,
email: this.state.email,
password: this.state.password
})
})
.then(response => response.json())
.then(res => {
console.log(res)
})
}
在这里,我正在将一些数据发送到django。以发送csrf令牌,我正在根据文档使用“ react-cookie”。但是在python方面显示 禁止(未设置CSRF cookie):/ register / [11 / Nov / 2018 11:56:33]“ POST / register / HTTP / 1.1” 403 2868