美文网首页DRF
DRF使用simpleJWT记录

DRF使用simpleJWT记录

作者: 维京时代 | 来源:发表于2020-09-15 15:46 被阅读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

    相关文章

      网友评论

        本文标题:DRF使用simpleJWT记录

        本文链接:https://www.haomeiwen.com/subject/ywdfyktx.html