gpt4 book ai didi

django-rest-framework - Django Rest Framework 面板 - 登录和注销不适用于 Simple JWT

转载 作者:行者123 更新时间:2023-12-05 06:56:51 28 4
gpt4 key购买 nike

我正在使用 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 header 执行注销/登录吗?我得到的错误是这样的,即使在提供了正确的凭据之后也是如此:

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."
}

最佳答案

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

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}

关于django-rest-framework - Django Rest Framework 面板 - 登录和注销不适用于 Simple JWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65029620/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com