加入jwt验证后,401错误

来源:8-5 用户收藏功能和vue联调

weixin_慕容7254231

2023-03-28

加上这段代码后,收藏报401错误,
# authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication)

permission_classes = (IsAuthenticated, IsOwnerOrReadOnly)
authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication)
serializer_class = UserFavSerializers
lookup_field = 'goods_id'	

Settings配置

# JWT配置 里面具体配置可以参考文档
SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=7),  # 配置过期时间
    'REFRESH_TOKEN_LIFETIME': timedelta(days=15),
}

前端请求时带上了Authorization

Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjgwNTg5NjI4LCJpYXQiOjE2Nzk5ODQ4MjgsImp0aSI6ImRhNTFlMDczMDc3YjRmYTZhYWFiYzU0ODZhZDUxZTI2IiwidXNlcl9pZCI6MX0.HlUgxsr58XGOjrqwl0P4qBaCrEYa6o7eyBt_SxS1YnY
Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjc5OTg5NTgwLCJpYXQiOjE2Nzk5ODkxNjAsImp0aSI6IjhkNWQxOGFjNWI2MzQyNGM4YWY4MzAzMmU2YWI2NjUyIiwidXNlcl9pZCI6MX0.5f_4zbn4qhHzi3LqHR90iH7vBOHb7-gH99fwFGUB5DQ

这两个Authorization都是报错401

写回答

1回答

bobby

2023-03-29

'ACCESS_TOKEN_LIFETIME': timedelta(minutes=7) 你这个过期时间只有7分钟也太短了吧,你图啥呀!

0
3
慕姐7020064
回复
weixin_慕容7254231
我也有这个问题,怎么解决的
2023-09-08
共3条回复

Python前后端分离开发Vue+Django REST framework实战

Django REST framework课程视频,RESTFul API前后端分离开发

2873 学习 · 2457 问题

查看课程