路由重定向1、路由重定向2、视图重定向

This commit is contained in:
mxjdi 2025-04-26 23:18:10 +08:00
parent 7807b60170
commit 3f1a01d942
3 changed files with 3 additions and 0 deletions

View File

@ -46,6 +46,7 @@ urlpatterns = [
# 媒体路由
re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
# 路由重定向用RedirectVIew实现
# 访问http://localhost:8000/redirectTo直接跳转到http://localhost:8000/index/
path('redirectTo',RedirectView.as_view(url="index/")),

View File

@ -5,6 +5,7 @@
<title>Title</title>
</head>
<body>
系统运行有问题
</body>
</html>

View File

@ -9,6 +9,7 @@ def index(request):
def blog(request, id):
#输入http://localhost:8000/blog/0会跳转到http://localhost:8000/static/error.html
if id==0:
return redirect("/static/error.html")