DRF

DRF使用simpleJWT记录

2020-09-15  本文已影响0人  维京时代

安装

pip install djangorestframework_simplejwt

设置配置文件

在项目setting.py文件中做如下设置

"DEFAULT_PERMISSION_CLASSES": [
        "rest_framework.permissions.IsAuthenticated",
    ],
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    ),

设置路由

在项目主urls.py文件中做如下设置

urlpatterns = [
    path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
    path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
    path("api/token/verify/", TokenVerifyView.as_view(), name="token_verify"),
]

用POSTMAN检验是否可以获取token

image.png

访问普通页面,看看jwt是否生效了

1.没有token的时候

image.png

2.有token的时候

image.png
上一篇 下一篇

猜你喜欢

热点阅读