南强小屋 Design By 杰米
其实就是利用{% block xxx %} {% endblock %}的方式定义一个块,相当于占位。存放在某个html中,比如base.html
然后在需要实现这些块的文件中,使用继承{% extends "base.html" %}的方式引入母板文件,然后在{% block xxx %}......{% endblock %}块定义中实现具体的内容。
base.html示例:注意块的定义。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="http://v3.bootcss.com/favicon.ico" rel="external nofollow" >
<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="external nofollow" >
<title>所有的书都在这里</title>
{% block page_css %}
{% endblock %}
{% block page_js %}
{% endblock %}
<!-- Bootstrap core CSS -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="external nofollow" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://v3.bootcss.com/examples/dashboard/dashboard.css" rel="external nofollow" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="/UploadFiles/2021-04-08/ie8-responsive-file-warning.js">
某个继承页:
{# 继承母板 #}
{% extends 'base.html' %}
{% block book_class %}
active
{% endblock %}
{% block page_css %}
{% load static %}
<link rel="stylesheet" href="{% get_static_prefix %}book_list_only.css" rel="external nofollow" >
{% endblock %}
{#把自己页面的内容,填入母板里面相应的位置#}
{% block main_body %}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">我是自定义内容,用来替换母板中指定的位置</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-8"> </div>
<div class="col-md-4"><a href="/add_book/" rel="external nofollow" rel="external nofollow" class="btn btn-primary"><i class="fa fa-plus-square"></i> 添加新书</a>
<a href="/add_publisher/" rel="external nofollow" rel="external nofollow" class="btn btn-success"><i class="fa fa-plus-square"></i> 添加出版社</a></div>
</div>
<table class="table table-dark table-hover">
<thead>
<tr>
<th>#</th>
<th>id</th>
<th>名称</th>
<th>出版社</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for b in books %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ b.id }}</td>
<td>{{ b.title }}</td>
<td>{{ b.publisher.name }}</td>
<td>
<a href="/del_book/" rel="external nofollow" class="btn btn-danger"><i class="fa fa-trash fa-fw"></i>删除</a>
<a href="/edit_book/" rel="external nofollow" class="btn btn-info"><i class="fa fa-pencil fa-fw"></i>编辑</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
另一个继承页:
{% extends "base.html" %}
{% block main_body %}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">所有的出版社</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-8"> </div>
<div class="col-md-4"><a href="/add_book/" rel="external nofollow" rel="external nofollow" class="btn btn-primary"><i class="fa fa-plus-circle fa-fw"></i>添加新书</a>
<a href="/add_publisher/" rel="external nofollow" rel="external nofollow" class="btn btn-success"><i class="fa fa-plus-circle fa-fw"></i>添加出版社</a></div>
</div>
<table class="table table-dark table-hover">
<thead>
<tr>
<th>#</th>
<th>id</th>
<th>名称</th>
<th>地址</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for p in publisher %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ p.id }}</td>
<td>{{ p.name }}</td>
<td>{{ p.addr }}</td>
<td>
<a href="/del_publisher/" rel="external nofollow" class="btn btn-danger"><i class="fa fa-remove fa-fw"></i>删除</a>
<a href="/edit_publisher/" rel="external nofollow" class="btn btn-info"><i class="fa fa-edit fa-fw"></i>编辑</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
{% block publisher_class %}
active
{% endblock %}
完整的练习项目代码:day63_base_jb51.rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米
暂无python之django母板页面的使用的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。