我正在尝试在 GCP 上部署 django 应用程序,但是当我尝试进行迁移时,它给了我这个错误:
ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ModuleNotFoundError: No module named 'rest_framework_simplejwt'.
设置.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated'
],
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
]
}
SIMPLE_JWT = {
'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=800),
'REFRESH_TOKEN_LIFETIME': timedelta(days=2),
}
OAUTH2_PROVIDER = {
'ACCESS_TOKEN_EXPIRE_SECONDS': 60 * 15,
'OAUTH_SINGLE_ACCESS_TOKEN': True,
'OAUTH_DELETE_EXPIRED': True
}
要求.txt
django-cors-headers
pyjwt
djangorestframework
djangorestframework-jwt==1.11.0
我错过了什么?
更新
我安装了 rest_framework_simplejwt ,现在错误转移到:
No module named 'rest_framework_simplejwt.tokens'
最佳答案
看来你混淆了两个包。 djangorestframework-jwt
您在 requirements.txt 中的内容是 no longer maintained .它提供了 rest_framework_jwt.authentication.JSONWebTokenAuthentication
认证类。
但是,您实际使用的,rest_framework_simplejwt.authentication.JWTAuthentication
, 来自 pip 包 djangorestframework_simplejwt
所以你需要更新你的requirements.txt。删除 djangorestframework-jwt
并添加 djangorestframework_simplejwt
关于python - 导入错误 : Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57864306/