代码之家  ›  专栏  ›  技术社区  ›  Kadiem Alqazzaz

未提供Django身份验证凭据

  •  0
  • Kadiem Alqazzaz  · 技术社区  · 7 年前

    所以我使用Http文件发出GET请求 rest_framework 身份验证

    下面是我使用的命令:

    GET localhost:8000/api-admin/products
    Authorization: Token 5e2cf6ddc7a0ff8fe03e4749d788a423f6640443
    

    当我使用浏览器并转到该链接时,它会成功工作,但当我使用HTTP文件或邮递员时,我会得到 Authentication credentials were not provided. 错误

    REST_FRAMEWORK = {
        'DEFAULT_AUTHENTICATION_CLASSES': (
            'rest_framework.authentication.TokenAuthentication',
            'rest_framework.authentication.SessionAuthentication',
        )
    }
    
    0 回复  |  直到 7 年前
        1
  •  0
  •   wil.x2rt    7 年前

    我认为您必须在URL的末尾添加一个trailing/。

        2
  •  0
  •   Kadiem Alqazzaz    7 年前

    TokenAuthentication authentication_classes

    authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)