python - 无法从 JWT 导入 TokenObtainPairView、TokenRefreshView
问题描述
我想使用 Json Web 令牌身份验证。
但是当我导入时,它给了我没有找到 TokenObtainPairView、TokenRefreshView 参考的错误,但是我安装了 jwt。
网址.py:
from django.contrib import admin
from django.urls import path
from rest_framework_jwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
from django.conf.urls import url,include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/token/', TokenObtainPairView.as_view(),
name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(),
name='token_refresh'),
url(r'^auth/', include('authsystem.urls'))
设置.py:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
}
当我做 pip freeze 时,我有包:
Django==2.2.4
django-cors-headers==3.1.0
djangorestframework==3.10.2
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==4.3.0
Pillow==6.1.0
PyJWT==1.7.1
pytz==2019.2
sqlparse==0.3.0
我试图从不同的方式导入,但它仍然给我找不到参考。
解决方案
您从错误的框架导入它,您需要从rest_framework_simplejwt.views
模块导入它,而不是模块:rest_framework_jwt.views
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
djangorestframework-jwt
您同时安装and是否有特定原因djangorestframework-simplejwt
?
推荐阅读
- jupyter-notebook - Python Markdown 代码未在输出中编译
- powerquery - Power Query,逐行计算下 3 个值的总和
- ios - 分组功能时如何摆脱错误?
- r - “if”语句中的短路逻辑评估
- javascript - 不和谐音乐机器人问题
- iphone - iOS12 中的 EKCalendar 标题为空白
- python - Pandas - 将多个分类列转换为同一组列
- cuda - 在 CUDA 中每个网格(x 维度)启动超过 65536 个块
- git - GitHub 字体对齐问题:源代码查看器中的多余空格
- sql - 如何为 ColdFusion FindNoCase If 条件编写 SQL 查询?