3

我正在使用 DRF 创建一个后端 api。我创建了一个自定义用户模型,我使用 allauth 和 dj-rest-auth 进行身份验证。到目前为止一切顺利,我还在我的网址中添加了这条路径,以便 DRF 面板允许我登录和注销:

path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

当我还添加 Simple JWT 时,就会出现问题。登录/注销功能不再起作用,我只能通过 dj-rest-auth 路径执行身份验证。

urlpatterns = [
    ...,
    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls'))
]

有谁知道是否可以让 DRF 标头执行注销/登录?我得到的错误是这样的,即使提供了正确的凭据:

HTTP 401 Unauthorized
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
WWW-Authenticate: Bearer realm="api"

{
    "detail": "Authentication credentials were not provided."
}
4

1 回答 1

0

您是否将以下代码添加到 settings.py 中?

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}
于 2020-12-01T00:39:24.790 回答