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),
}
相关推荐
To_OC7 小时前
Next.js + Redis 构建笔记系统:Redis Hash 实战与性能优化
redis·后端·next.js
安_8 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
counting money9 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记10 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘10 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术11 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==11 小时前
JSON和Python的 四种核心容器
python·json
demo007x11 小时前
Hermes-Agent 技术架构
前端·后端·agent
__zRainy__13 小时前
Node系列 · Node基础:net 模块
后端·node.js