摘要: 需求如下: 用户输入:用户名或手机号或邮箱 +密码都能登录,并签发token 代码书写: model层配置(需要扩写auth_user表): from django.contrib.auth.models import AbstractUser class User(AbstractUser): m 阅读全文
posted @ 2024-01-03 21:12 wellplayed 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 定制返回格式 目标如下: 想要返回如下格式数据: { code:100, msg:'登录成功', username:'登录用户名字', access:asdfasdf.asdfasdf.asdfasdf refresh:asdfas.ere.we } 第一步:新建一个序列化类文件,以serializ 阅读全文
posted @ 2024-01-03 20:42 wellplayed 阅读(18) 评论(0) 推荐(0) 编辑
摘要: jwt的使用步骤 第一步:安装模块 pip install djangorestframework-simplejwt 第二步:注册app # settings文件配置 INSTALLED_APPS = [ ... 'rest_framework_simplejwt', ... ] 第三步:sett 阅读全文
posted @ 2024-01-03 20:35 wellplayed 阅读(9) 评论(1) 推荐(1) 编辑
摘要: access:真正使用的token refresh:用来更新access access过期时间很短,过期后,需要使用refresh重新生成access的token以保证token的安全 阅读全文
posted @ 2024-01-03 20:33 wellplayed 阅读(12) 评论(0) 推荐(0) 编辑
摘要: base64介绍 base64是编码解码方式,而不是加密方式 使用方法 首先需要导入base64模块 import base64 base64编码: 只能转换bytes格式数据 base64.b64encode(转换数据.encode('utf-8')) base64解码: base64编码可能需要 阅读全文
posted @ 2024-01-03 20:04 wellplayed 阅读(147) 评论(0) 推荐(0) 编辑