I want to use Json Web token authentication.
but when I import, it gives me error of no reference of TokenObtainPairView, TokenRefreshView, found, however I installed jwt.
urls.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'))
Settings.py:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
}
when I do pip freeze I have the packages:
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
I have tried to import from different way but still it giving me cannot find reference.
You imported it from the wrong framework, you need to import it from the rest_framework_simplejwt.views module, not the module:rest_framework_jwt.views
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
Is there a specific reason why you installed both djangorestframework-jwt and djangorestframework-simplejwt?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With