Django使用Token认证(simplejwt库的配置)

目录

官网文档

https://django-rest-framework-simplejwt.readthedocs.io/en/latest/

安装

bash 复制代码
pip install djangorestframework-simplejwt

项目配置

bash 复制代码
REST_FRAMEWORK = {
    ...
    'DEFAULT_AUTHENTICATION_CLASSES': (
        ...
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
    ...
}

拓展配置

bash 复制代码
# JWT扩展配置
import datetime
JWT_AUTH = {
    # 设置生成jwt token的有效时间
    'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7),
}
相关推荐
掘金码甲哥1 小时前
超性感的轻量级openclaw平替,我来给你打call
后端
用户8356290780514 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
啊哈灵机一动4 小时前
使用golang搭建一个nes 模拟器
后端
间彧5 小时前
SpringBoot + ShardingSphere 读写分离实战指南
后端
砍材农夫5 小时前
订单超时
后端
树獭叔叔6 小时前
06-大模型如何"学习":从梯度下降到AdamW优化器
后端·aigc·openai
markfeng86 小时前
Python+Django+H5+MySQL项目搭建
python·django
得鹿6 小时前
MySQL基础架构与存储引擎、索引、事务、锁、日志
后端
程序员飞哥6 小时前
Block科技公司裁员四千人,竟然是因为 AI ?
人工智能·后端·程序员
GinoWi6 小时前
Chapter 2 - Python中的变量和简单的数据类型
python