设置重定向响应

This commit is contained in:
mxjdi 2025-04-27 22:24:46 +08:00
parent 1fbd7cd401
commit a29a0137a9
5 changed files with 16 additions and 3 deletions

View File

@ -127,7 +127,7 @@ USE_TZ = True
STATIC_URL = 'static/'
# 设置静态资源文件集合
# STATICFILES_DIRS = [BASE_DIR / 'static', BASE_DIR / 'helloworld/images']
STATICFILES_DIRS = [BASE_DIR / 'static', BASE_DIR / 'helloworld/images']
# 设置媒体路由
MEDIA_URL = '/media/'

View File

@ -4,8 +4,11 @@ from django.shortcuts import render, redirect
# Create your views here.
def index(request):
print("页面请求处理中")
return render(request, 'index.html')
# redirect重定向permanent为True时永久重定向
return redirect("/static/new.html", permanent=True)
#return redirect("/blog/2")
# print("页面请求处理中")
# return render(request, 'index.html')
def blog(request, id):

View File

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

10
static/new.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
新页面
</body>
</html>