我有这个设置:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
]
}
而这个观点:
class Config(APIView):
def get(self, request, *args, **kwargs):
if 'config' in request.GET.dict():
if os.path.isfile(settings.CONFIG):
yaml = read_config(settings.CONFIG)
return Response(yaml)
else:
return Response({
"success": False,
"error": "config file not found!"})
else:
return Response({"success": False})
def post(self, request, *args, **kwargs):
if 'data' in request.data:
print(request.data['data'])
return Response({"success": False})
使用 axios 我管理我的 api 调用,例如:
axios.post('api/config/?config', { data: obj, headers: { Authorization: 'Bearer ' + rootState.auth.jwtToken } })
现在的问题是,我无法发布数据。我收到未经授权的(401) 错误,并在响应消息中显示:{"detail":"Authentication credentials were not provided."}
你能告诉我,我在这里缺少什么,我该如何解决这个问题?