Django模板之模板组件(include)
2024-09-07 14:33:17
可以将常用的页面内容如导航条,页尾信息等组件保存在单独的文件中的一个小功能块,然后在需要使用的地方,文件的任意位置按如下语法导入即可。
模板组件:
新建一个组件zujian.html文件(一个固定写好的静态页面)
在新的html文件中需要引入的位置加上include标签:{% include "zujian.html" %}
模板组件引用演示:
zujian.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.c1, .nav {margin: 0 auto;width: 1200px;background-color: #d6d6d6;color: white;}
.navleft {float: left;text-align: left;}
.navright {float: right;}
.fixed:after {content: "";display: block;clear: both;}
ul, li {list-style: none;display: inline;margin: 0;padding: 0;}
</style>
<title>模板组件</title>
</head>
<body>
<div class="c1">
<div class="nav fixed">
<div class="navleft ">
<ul>
<li>古诗</li>
<li>绝句</li>
<li>诗经</li>
</ul>
</div>
<div class="navright">
<ul>
<li>登录</li>
<li>注册</li>
</ul>
</div>
</div>
</div> </body>
</html>
zujian_demo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模板组件引入演示</title>
</head>
<body>
<div> {% include "zujian.html" %}</div>
<div><h1>模板组件引入演示(include标签可以放在任意位置)</h1></div>
<div> {% include "zujian.html" %}</div>
</body>
</html>
views.py
def zujian(request):
return render(request,"zujian.html")
def zujian_demo(request):
return render(request,"zujian_demo.html")
结果演示:
最新文章
- oracle pl/sql split函数
- Python asyncio库的学习和使用
- Response.Redirect引起的“无法在发送HTTP标头之后进行重定向”
- MS SQL SERVER 数据库日志压缩方法与代码
- Regarding the %EDIT table
- BAT及各大互联网公司2014前端笔试面试题:HTML/CSS篇
- visual studio 辅助工具
- 基于MongoDB打造.Net的分布式Session子系统
- pro文件常用内容
- 汽车之家店铺商品详情数据抓取 DotnetSpider实战[二]
- cnzz流量统计
- springboot~application.properties和application.yml的使用
- 【Wyn Enterprise BI知识库】 认识多维数据建模与分析 ZT
- MySQL复制ERROR 1794 (HY000): Slave is not configured or failed to initialize properly.
- 微服务的发现与注册--Eureka
- SKU与SPU
- 20165310java_teamExp1_week1
- dp练习(11)——石子并归
- ntp服务的细节全解析
- 26.OGNL与ValueStack(VS)-N语法top语法