问题描述
当我退出并尝试发布它时,但当我登录并尝试发布时它不起作用并给我 403 错误,
反应文件
class Axios extends React.Component{
constructor(){
super()
this.state = {
persons: []
}
}
post(){
axios.post('http://127.0.0.1:8000/api/create',{
title: 'titan',body: 'this is working',headers:{
withCredentials: true,'X-CSrftoken':CSRF_TOKEN,'Accept': 'application/json','Content-Type': 'application/json',},})
.then(function (response) {
console.log(response);
})
}
get(){
axios.get('http://127.0.0.1:8000/api').then(Response=>{
console.log(Response.data)
})
}
componentDidMount(){
this.post();
this.get();
}
render(){
return(
<div>
<h1>fetch</h1>
</div>
)
}
}
export default Axios;
views.py
class create(CreateAPIView):
queryset = Post.objects.all()
serializer_class = postSerializers
也在setting.py中添加了这个
CSRF_COOKIE_NAME = "X-CSrftoken"
登录时
退出时
如果有足够聪明的人请帮助我解决这个问题......试图找到解决方案数天......
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)