目录
一、中间件 mymiddelware.py 文件
from django.utils.deprecation import MiddlewareMixin from django.shortcuts import render, HttpResponse, redirect class MyMiddleware(MiddlewareMixin): def process_request(self, request): url = request.get_full_path() print(url) # print(request.path) is_login = request.session.get('is_login', None) if is_login or url.startswith('/appCsrf/csrf_login/'): print(is_login) return else: print('is_login is none') # 返回login页面重新登陆,next表示从哪个页面返回 return redirect('/appCsrf/csrf_login/?ne