自定义中间件
This commit is contained in:
parent
84f2eae72d
commit
ed07489c52
@ -46,6 +46,7 @@ MIDDLEWARE = [
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'helloWorld.mymid.md1.Md1',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'Django5.urls'
|
||||
@ -73,8 +74,12 @@ WSGI_APPLICATION = 'Django5.wsgi.application'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'django',
|
||||
'USER': 'django',
|
||||
'PASSWORD': '123456789',
|
||||
'HOST': '148.135.85.49',
|
||||
'PORT': '3306',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
helloWorld/mymid/md1.py
Normal file
10
helloWorld/mymid/md1.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
|
||||
class Md1(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
print("request请求来了")
|
||||
|
||||
def process_response(self, request, response):
|
||||
print("请求处理完毕,将放回到页面")
|
||||
return response
|
||||
@ -3,4 +3,5 @@ from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
return render(request, 'index2.html')
|
||||
print("页面请求处理中")
|
||||
return render(request, 'index.html')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user