如何在模板中显示导航页面的路径结构(站点地图)
Posted
技术标签:
【中文标题】如何在模板中显示导航页面的路径结构(站点地图)【英文标题】:How to show the path structure of navigated pages in templates ( Site Map ) 【发布时间】:2020-01-07 00:20:28 【问题描述】:如何在页面内显示页面路径?我的想法是使用链接来实现路径,就像操作系统中的目录结构一样。我怎样才能实现这样的东西?
你在这里:
首页 > 分类 > 产品 > 鞋子 > 运动鞋 > 篮球 > 耐克
这些必须是链接,以便用户点击这些链接时,会打开以下页面。
【问题讨论】:
谷歌在 html 中的“面包屑”或者你使用的任何 cms 或平台。 【参考方案1】:试试这个代码或从 url https://mega.nz/#!UjR0iSbI!R2OUwlFtUePM7IvAGnQTBj17F8St-ZwjllSmPcR3pMc 下载源代码并阅读 readme.md 文件
view.py
from django.shortcuts import render
def home(request):
w = "Home"
context =
'ww': w,
return render(request, "home.html", context)
def Category(request):
w = "Category"
context =
'ww': w,
return render(request, "Category.html", context)
def Products(request):
w = "Products"
context =
'ww': w,
return render(request, "Products.html", context)
def Shoes(request):
w = "Shoes"
context =
'ww': w,
return render(request, "Shoes.html", context)
def Sports_Shoes(request):
w = "Sports Shoes"
context =
'ww': w,
return render(request, "Sports_Shoes.html", context)
def Basketball(request):
w = "Basketball"
context =
'ww': w,
return render(request, "Basketball.html", context)
def Nike(request):
w = "Nike"
context =
'ww': w,
return render(request, "Nike.html", context)
在模板目录中创建 home.html、Category.html、Products.html、Shoes.html、Sports_Shoes.html、Basketball.html、Nike.html
然后将以下代码粘贴到所有的html页面中,代码中不需要做任何改动
% load static %
<html lang="en">
<head>
<link rel="stylesheet" href='% static "css/style.css" %'>
<meta charset="UTF-8">
<title>ww</title>
</head>
<body>
<a id = "a1" href="http://127.0.0.1:8000/">Home </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Category">Category </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Products">Products </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Shoes">Shoes </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Sports_Shoes">Sports_Shoes </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Basketball">Basketball </a>
<b id = "b1" > >>> </b>
<a id = "a1" href="http://127.0.0.1:8000/Nike">Nike </a>
<h1 id="welcome">ww</h1>
</body>
</html>
如果您有其他端口,请从 html 代码更改端口 8000 **添加 static > css > style.css 并复制粘贴此代码
#welcome
font-size:200px;
margin: 4px;
padding: 12px;
body
background-color: burlywood;
** 现在添加到 urls.py
urlpatterns = [
path('', views.home, name='home'),
path('Category', views.Category, name='Category'),
path('Products', views.Products, name='Products'),
path('Shoes', views.Shoes, name='Shoes'),
path('Sports_Shoes', views.Sports_Shoes, name='Sports_Shoes'),
path('Basketball', views.Basketball, name='Basketball'),
path('Nike', views.Nike, name='Nike'),
path('admin/', admin.site.urls),
]
【讨论】:
【参考方案2】:如果你想在 django 模板中使用它,你可以试试this。
【讨论】:
以上是关于如何在模板中显示导航页面的路径结构(站点地图)的主要内容,如果未能解决你的问题,请参考以下文章