I built an API that the users are authenticated with a token
class BaseViewSet(ModelViewSet):
authentication_class = (TokenAuthentication,)
permission_classes = [IsAuthenticated,]
and I have been trying to request the data with this fetch
const get_players = async() =>{
const response = await fetch(url,{
credentials: 'include',
headers:{
Authorization: `token ${token}`
}
})
const data = await response.json()}
But I get this error in console:
GET https: * the url * (Forbidden)
get_players
(anonymous)
Any idea what the problem is?
It seems like it should work as written. But obviously it doesn't think you're authorized. So either the token is wrong, or the pay you are passing it in is wrong.
Do you have any docs for the header format.
I've seen token ${token}
and Bearer ${token}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.