Django第15部分中,如何实现页面间的跳转操作?

2026-06-10 22:552阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计373个文字,预计阅读时间需要2分钟。

Django第15部分中,如何实现页面间的跳转操作?

学习笔记,仅供参考,有误请纠正+模板+页面跳转+因为我不知道如何详细描述,所以直接放代码,我们一起来看看具体效果。+pages.+++ + Yes!++++++

学习笔记,仅供参考,有错必纠


模板



Django第15部分中,如何实现页面间的跳转操作?

页面跳转



因为我不知道咋描述,所以直接放代码,我们一起来细细品味。



pages.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Yes!</title>
</head>
<body>
<ul>
<li><a href="/page2_template/" >第2个模板</a></li>
<li><a href="/page3_template/" >第3个模板</a></li>
<li><a href="/page4_template/" >第4个模板</a></li>
</ul>

</body>
</html>

我们在pages.html页面中添加了3个通往其他页面的超链接.



urls.py

urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'page2_template/$', views.page2_template),
re_path(r'page3_template/$', views.page3_template),
re_path(r'page4_template/$', views.page4_template),
re_path(r'pages/$', views.pages),
]



views.py

def pages(request):
return render(request, "pages.html")

向127.0.0.1:8000/pages/发起请求:

点击"第2个模板":

可以看到,我们成功跳转到路由为​​page2_template/​​的页面


本文共计373个文字,预计阅读时间需要2分钟。

Django第15部分中,如何实现页面间的跳转操作?

学习笔记,仅供参考,有误请纠正+模板+页面跳转+因为我不知道如何详细描述,所以直接放代码,我们一起来看看具体效果。+pages.+++ + Yes!++++++

学习笔记,仅供参考,有错必纠


模板



Django第15部分中,如何实现页面间的跳转操作?

页面跳转



因为我不知道咋描述,所以直接放代码,我们一起来细细品味。



pages.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Yes!</title>
</head>
<body>
<ul>
<li><a href="/page2_template/" >第2个模板</a></li>
<li><a href="/page3_template/" >第3个模板</a></li>
<li><a href="/page4_template/" >第4个模板</a></li>
</ul>

</body>
</html>

我们在pages.html页面中添加了3个通往其他页面的超链接.



urls.py

urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'page2_template/$', views.page2_template),
re_path(r'page3_template/$', views.page3_template),
re_path(r'page4_template/$', views.page4_template),
re_path(r'pages/$', views.pages),
]



views.py

def pages(request):
return render(request, "pages.html")

向127.0.0.1:8000/pages/发起请求:

点击"第2个模板":

可以看到,我们成功跳转到路由为​​page2_template/​​的页面