You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

19 lines
579 B

from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect
import re
class PermissionMiddleware(MiddlewareMixin):
def process_request(self, request):
curr_path = request.path
print(curr_path)
# 白名单
white_list = ['/myuser_login/', '/myuser_reg']
for w in white_list:
if re.search(w, curr_path):
return None
# 验证登录
print(request.user.is_authenticated)
if not request.user.is_authenticated:
return redirect('/myuser_login/')