From ed07489c52910be9d0dd1d3f8c0b734dd9e57bda Mon Sep 17 00:00:00 2001 From: mxjdi Date: Sat, 26 Apr 2025 21:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Django5/settings.py | 9 +++++++-- helloWorld/mymid/md1.py | 10 ++++++++++ helloWorld/views.py | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 helloWorld/mymid/md1.py diff --git a/Django5/settings.py b/Django5/settings.py index 83918f8..1e794b8 100644 --- a/Django5/settings.py +++ b/Django5/settings.py @@ -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', } } diff --git a/helloWorld/mymid/md1.py b/helloWorld/mymid/md1.py new file mode 100644 index 0000000..ef1cff4 --- /dev/null +++ b/helloWorld/mymid/md1.py @@ -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 \ No newline at end of file diff --git a/helloWorld/views.py b/helloWorld/views.py index 3ad7b04..3de4d97 100644 --- a/helloWorld/views.py +++ b/helloWorld/views.py @@ -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')