当前位置:网站首页>Package JWT
Package JWT
2022-07-27 05:38:00 【Csdn__ F】
You need to create a folder under the root directory 
Write code in it
import jwt, time
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
class UserMiddleware(MiddlewareMixin):
def process_request(self, request):
# Get the information sent by the front desk
token = request.META.get('HTTP_TOKEN')
# Decrypt
try:
user = jwt.decode(token, settings.SECRET_KEY, algorithms='HS256')
# Judge whether it is overdue
if user['exp'] < int(time.time()):
user = None
except:
user = None
# Insert to view at time
request.META['USER'] = user
In the configuration project
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware'
]
边栏推荐
猜你喜欢

Sharing force buckle-189. Three solutions of rotation array

函数和箭头函数

初识C语言——字符串+转义字符+注释

分享一道关于程序编译过程的选择题(内含编译过程浅谈,符号表的形成合并过程)

Li Hongyi machine learning team learning punch in activity day02 --- return

Program environment and preprocessing (Part 1): how does a program run successfully?

Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()

JS中apply、call、bind的区别

强制登录,七牛云上传图片

Looking at the PK of alphago and Li Shishi from a deep perspective
随机推荐
[codeworks round 801 div2 D tree queries] tree greedy conclusion
用户页面管理
JS==操作符的强制类型转换规定
C语言进制转换以及原补反码位运算介绍
页面的基本布局
JS中原型及原型链
2021 Niuke multi school training camp 5 (question b)
Hi3516DV300环境搭建
Xiaomi mall project_ register
通用视图,DRF视图回顾
背景图片相关应用-铺满,自适应
Makefile is easy to understand and explain
First knowledge of C language - why does every C program have a main function
JS中如何判断一个对象是空对象
后台实现spu管理
JS中forEach和map方法有什么区别
弹性盒/伸缩盒(flex)的使用
规格管理,及规格选项管理功能实现
Li Hongyi machine learning team learning punch in activity day05 --- skills of network design
First knowledge of C language -- what is C language