Django extend(继承)模板标签
2024-10-05 08:15:50
在 views.py 上修改
...
def ordered(req):
return render(req, "ordered.html")
def shopping_car(req):
return render(req, "shopping_car.html")
在 urls.py 上修改
...
path('ordered/', views.ordered),
path('shopping_car/', views.shopping_car),
...
在 tmplates 文件夹下创建 base.html 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.page-header{
height:50px;
background-color: rebeccapurple;
}
.page-body .menu{
height: 500px;
background-color: antiquewhite;
float: left;
width: 20%;
}
.page-body .content{
height: 500px;
background-color: cornflowerblue;
float: left;
width: 80%
}
.page-footer{
height:50px;
background-color: green;
clear: both;
}
</style>
</head>
<body>
<div>
<div class="page-header"></div>
<div class="page-body">
<div class="menu">
<a href="/ordered/">订单</a><br>
<a href="/shopping_car/">购物车</a>
</div>
{% block content %}
{% endblock %}
</div>
<div class="page-footer"></div>
</div>
</body>
</html>
ordered.html 文件
{% extends "base.html" %}
{% block content %}
<div class="content">
订单
</div>
{% endblock %}
shopping_car.html 文件
{% extends "base.html" %}
{% block content %}
<div class="content">
购物车
</div>
{% endblock %}
效果如下:
最新文章
- 使用Nito.AsyncEx实现异步锁(转)
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
- 第 15 章 CSS 文本样式[下]
- Spring Data JPA 查询方法支持的关键字
- Centos 安装 neo4j
- sencha touch api 使用指南
- PANIC : Error configuring AvalonLogSystem :
- 写Java程序让Jvm崩溃
- 教程-Delphi操作快捷键
- 无Xaml的WPF展示
- JSP使用JDBC ODBC 实例
- web page diagnostics
- Datatbel和 string之间的相互转换
- 水dp第二天(背包有关)
- 【CF734F】Anton and School(构造)
- Python学习笔记 -- 第一章
- stm32学习基本知识点
- 【kuangbin专题】计算几何_半平面交
- js中定时器之一
- highcharts柱状图实现legend和数据列一一对应效果