路由重定向1、路由重定向2、视图重定向
This commit is contained in:
parent
7807b60170
commit
3f1a01d942
@ -46,6 +46,7 @@ urlpatterns = [
|
|||||||
# 媒体路由
|
# 媒体路由
|
||||||
re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
|
re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
|
||||||
|
|
||||||
|
|
||||||
# 路由重定向,用RedirectVIew实现
|
# 路由重定向,用RedirectVIew实现
|
||||||
# 访问http://localhost:8000/redirectTo直接跳转到http://localhost:8000/index/
|
# 访问http://localhost:8000/redirectTo直接跳转到http://localhost:8000/index/
|
||||||
path('redirectTo',RedirectView.as_view(url="index/")),
|
path('redirectTo',RedirectView.as_view(url="index/")),
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
<title>Title</title>
|
<title>Title</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
系统运行有问题
|
系统运行有问题
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -9,6 +9,7 @@ def index(request):
|
|||||||
|
|
||||||
|
|
||||||
def blog(request, id):
|
def blog(request, id):
|
||||||
|
|
||||||
#输入http://localhost:8000/blog/0会跳转到http://localhost:8000/static/error.html
|
#输入http://localhost:8000/blog/0会跳转到http://localhost:8000/static/error.html
|
||||||
if id==0:
|
if id==0:
|
||||||
return redirect("/static/error.html")
|
return redirect("/static/error.html")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user