小编Goo*_*nic的帖子

无法为 API 设置“DEFAULT_AUTHENTICATION_CLASSES”导入“rest_framework_jwt.authentication.JSONWebTokenAuthentication”

完整错误:无法为 API 设置“DEFAULT_AUTHENTICATION_CLASSES”导入“rest_framework_jwt.authentication.JSONWebTokenAuthentication”。ImportError:无法从“django.utils.encoding”导入名称“smart_text”

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}
Run Code Online (Sandbox Code Playgroud)

这是虚拟环境中的 pip freeze:

(backend) PS D:\js\backend> pip freeze                          
asgiref==3.5.1
Django==4.0.4
django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==5.1.0
mysqlclient==2.1.0
PyJWT==1.7.1
pytz==2022.1
sqlparse==0.4.2
tzdata==2022.1
Run Code Online (Sandbox Code Playgroud)

在错误的中间,它解决了装饰器的views.py中的一些行:

from http.client import HTTPResponse
from multiprocessing import context
from django.shortcuts import render
from django.http import HttpResponse, Http404, JsonResponse
from .models import Tweet
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import api_view, permission_classes
from rest_framework import status
Run Code Online (Sandbox Code Playgroud)

我不确定它们是否有关联

django django-views django-authentication jwt django-rest-framework

7
推荐指数
1
解决办法
1万
查看次数