我已经安装了djangorestframework-simplejwt
软件包并尝试导入该模块,urls.py
但views.py
仍然无法正常工作。请指导我解决这个问题。
点子列表
Package Version
----------------------------- -------
asgiref 3.3.1
Django 3.1.4
djangorestframework 3.12.2
djangorestframework-simplejwt 4.6.0
pip 20.2.3
PyJWT 1.7.1
pytz 2020.4
setuptools 49.2.1
sqlparse 0.4.1
设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Django_MedicalApp',
'rest_framework',
'rest_framework_simplejwt',]
REST_FRAMEWORK = {'DEFAULT_AUTHENTICATION_CLASSES':
['rest_framework_simplejwt.authentication.JWTAuthentication',],
'DEFAULT_PERMISSION_CLASSES':
('rest_framework.permissions.AllowAny','rest_framework.permissions.IsAuthenticatedOrReadOnly',)}
网址.py
from rest_framework_simplejwt.views import TokenObtainPairView
router = routers.DefaultRouter()
router.register('Company',views.CompanyViewset,basename='Company')
urlpatterns = [
path('admin/', admin.site.urls),
path('api/',include(router.urls),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'))]
视图.py
from rest_framework_simplejwt.authentication import JWTAuthentication
class CompanyViewset(viewsets.ViewSet):
authentication_classes = [JWTAuthentication]
请帮我解决这个导入错误。