我正在用DRF创建一个后端api。我创建了一个自定义用户模型,我使用allauth和dj-rest-auth进行身份验证。到目前为止,我还将以下路径添加到我的urls中,以便DRF面板允许我登录和注销:
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]当我还添加了简单的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."
}发布于 2020-12-01 08:39:25
您是否将以下代码添加到settings.py中?
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}https://stackoverflow.com/questions/65029620
复制相似问题