我正在使用带有React的Django,我可以使用http://127.0.0.1:8000/rest-auth/login/'登录用户并使用http://127.0.0.1:8000/rest-auth/registration/注册用户
我想获得当前用户:
axios.get('http://127.0.0.1:8000/rest-auth/user/')
.then(res => {
console.log(res)
})
但是我收到以下错误:
GET http://127.0.0.1:8000/rest-auth/user/ 403 (Forbidden)
我也在postman上尝试过,我得到以下内容:
{
"detail": "Authentication credentials were not provided."
}
有人能告诉我正确的方法吗?提前致谢。
这是因为你的路线需要Authorization token
。
axios.get('http://127.0.0.1:8000/rest-auth/user/, {
headers: {'Authorization': "Bearer " + token}
})
.then(res => {
console.log(res)
})