Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未提供Django和Angular POST凭据_Django - Fatal编程技术网

未提供Django和Angular POST凭据

未提供Django和Angular POST凭据,django,Django,错误当我尝试登录到我的项目时,我使用邮递员测试登录并向我发送错误 “详细信息”:“未提供身份验证凭据。” 我的url.py urlpatterns = [ url(r'^api-login-user$', views.LoginUserView.as_view()), url(r'^', TemplateView.as_view(template_name='angular/index.html')), url(r'^', include(router.urls)),

错误当我尝试登录到我的项目时,我使用邮递员测试登录并向我发送错误 “详细信息”:“未提供身份验证凭据。”

我的url.py

urlpatterns = [ 
    url(r'^api-login-user$', views.LoginUserView.as_view()),
   url(r'^', TemplateView.as_view(template_name='angular/index.html')),
     url(r'^', include(router.urls)),
    url(r'^auth/', ObtainAuthToken.as_view()),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
   ]

我的观点.py


class LoginUserView(APIView):

    def post(self, request, *args, **kwargs):
        username = request.data.get('username')
        password = request.data.get('password')

        user = authenticate(username=username, password=password)
        if user:
            payload = jwt_payload_handler(user)
            token = {
                'token': jwt.encode(payload, SECRET_KEY),
                'status': 'success'
                }            
            return Response(token)
        else:
            return Response(
              {'error': 'Invalid credentials',
              'status': 'failed'},
            )

我的设置.py

REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [
           'rest_framework.permissions.AllowAny', 'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.IsAdminUser' 
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication', 
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ],

     'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
}

那么如何在postman中发送请求参数呢?现在给我发送其他错误“zone.js:2969 POST 401(Unauthorized)”当我尝试登录时,我使用json Btwy发送数据您使用的是django_rest framework_apiew,但您的代码缺少一些重要部分,请将此作为参考,你可以尝试用表单数据而不是json发送凭证信息,只是为了确定你如何在postman中发送请求参数?现在给我发送其他错误“zone.js:2969 POST 401(Unauthorized)”当我尝试登录时,我用json Btwy发送数据你使用的是django_restframework_apiview,但你的代码缺少一些重要部分,将此作为参考,您也可以尝试以表单数据而不是json的形式发送凭证信息,以确保