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),
}
相关推荐
2501_936146041 分钟前
烟草叶片病害检测_YOLO11-C3k2-MSBlock模型详解
python
Data_agent13 分钟前
Python 编程实战:函数与模块化编程及内置模块探索
开发语言·python
十铭忘16 分钟前
windows系统python开源项目环境配置1
人工智能·python
Generalzy33 分钟前
langchain deepagent框架
人工智能·python·langchain
栈与堆38 分钟前
LeetCode 19 - 删除链表的倒数第N个节点
java·开发语言·数据结构·python·算法·leetcode·链表
一 乐41 分钟前
绿色农产品销售|基于springboot + vue绿色农产品销售系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·宠物
3***68841 小时前
Spring Boot中使用Server-Sent Events (SSE) 实现实时数据推送教程
java·spring boot·后端
C***u1761 小时前
Spring Boot问题总结
java·spring boot·后端
上进小菜猪1 小时前
基于 YOLOv8 的人体与行人检测智能识别实战 [目标检测完整源码]
后端
万行1 小时前
机器学习&第二章线性回归
人工智能·python·机器学习·线性回归