from django.http import JsonResponse
from rest_framework import status
from django.utils.deprecation import MiddlewareMixin
from common.libs import verity_token
import logging
logger = logging.getLogger('mylogger')
class Token(MiddlewareMixin):
"""
自定义中间件-验证token
"""
def process_request(self, request):
token = request.META.get('HTTP_AUTHORIZATION').strip()
if not token:
return JsonResponse({"status_code": 401, "msg": "未携带token(No token is carried.)"},
status=status.HTTP_401_UNAUTHORIZED)
if verity_token(token) == False:
return JsonResponse({"status_code": 401, "msg": "token验证失败(Token verification failed)"},
status=status.HTTP_401_UNAUTHORIZED)
django 自定义中间件
最新推荐文章于 2024-03-16 09:30:00 发布
关键词由CSDN通过智能技术生成