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.
20 lines
692 B
20 lines
692 B
6 months ago
|
from django.utils.deprecation import MiddlewareMixin
|
||
|
from django.shortcuts import render,redirect
|
||
|
|
||
|
class UserMiddleware(MiddlewareMixin):#django中有三个中间键
|
||
|
def process_request(self,request):
|
||
|
path = request.path_info
|
||
|
if path == '/SS01/login/' or path == '/SS01/register/':
|
||
|
return None
|
||
|
else:
|
||
|
if not request.session.get('username'):# 如果进入了/SS01/index这样的地址
|
||
|
return redirect('/SS01/login/')
|
||
|
else:
|
||
|
return None
|
||
|
|
||
|
|
||
|
def process_view(self,request,callback,callback_args,callback_kwargs):
|
||
|
pass
|
||
|
|
||
|
def process_response(self,request,response):
|
||
|
return response
|