【发布时间】:2017-08-28 19:59:59
【问题描述】:
我在标头中传递令牌(我已经从控制台知道),如下面的代码所示,并希望在该用户通过身份验证后来自该本地主机的数据,但在我的 android 模拟器上它显示错误 Cannot convert undefined or null to object
登录.js
componentDidMount() {
return fetch('http://10.42.0.1:8000/stocks/',
{
method: "GET",
headers:
{
'Authorization': `Bearer ${"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNhbSIsInVzZXJfaWQiOjYxLCJlbWFpbCI6IiIsImV4cCI6MTUwMzk0ODYyMH0.l4VLMLXcSZ7nOmKmjblLKFr0lTSpgYeFks_JeYiO7cU"}`
}
})
...
}
在views.py中
class Stocks(APIView):
permissions_classes = [IsAuthenticated]
authentication_classes= (TokenAuthentication,)
def get(self,request):
stocks=stock.objects.all()
serailizer=serial(stocks,many=True)
return Response(serailizer.data)
此处令牌未到达服务器,因此未授予权限。 我们正在使用 Django rest jwt 令牌。 谢谢你
【问题讨论】:
标签: django api react-native django-rest-framework react-native-android