如何在django-rest框架中扩展JWTAuthentication

如何在django-rest框架中扩展JWTAuthentication,django,django-rest-framework,django-rest-framework-simplejwt,Django,Django Rest Framework,Django Rest Framework Simplejwt,我创建了CustomAuthentication类,这个类扩展了JWTAuthentication类。我将这个类放在auth.py文件中,并与settings.py放在同一位置 在settings.py中,我修改: REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( '

我创建了CustomAuthentication类,这个类扩展了JWTAuthentication类。我将这个类放在auth.py文件中,并与settings.py放在同一位置

在settings.py中,我修改:

REST_FRAMEWORK = {

'DEFAULT_PERMISSION_CLASSES': (

'rest_framework.permissions.IsAuthenticated',

),

'DEFAULT_AUTHENTICATION_CLASSES': (

'rest_framework_simplejwt.authentication.JWTAuthentication',

),

}

但它不起作用,它抛出

无法为API设置“默认\u身份验证\u类”导入“auth.CustomAuthentication”。ImportError:模块“auth”未定义“CustomAuthentication”属性/类

以下是auth.py的内容:

from rest_framework_simplejwt.authentication import JWTAuthentication
class CustomJWTAuthentication(JWTAuthentication):
    is_valid = True
这里怎么了?请帮忙


非常感谢。

auth.py中的类名是“CustomJWTAuthentication”,您正在settings.py中使用“CustomAuthentication”,更改它,使两者相同。

是否已在settings.py中导入auth.py文件?请尝试“appname.auth.CustomAuthentication”,其中appname是应用程序的名称。@HeisAif:如何将答案标记为已接受?单击答案左侧的复选标记,将其从灰色切换为绿色。
from rest_framework_simplejwt.authentication import JWTAuthentication
class CustomJWTAuthentication(JWTAuthentication):
    is_valid = True