2018-09-08-Python全栈开发day50-django视图与模板-part3-继承
需求分析:
当某个html页面中有多个主题,当点击某一主题时,其他主题内容不变,只有其中一个变化
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .title{ height: 100px; width: 100%; background-color: aqua; text-align: center; float: left; } .title1{ float: left; position: relative; left: 35%; text-align: center; margin: 50px; line-height: 0; } .gongneng{ float: left; height: 999px; width:50%; background-color: beige; text-align: center; } .neirong{ display: block; } </style> </head> <body> {% block title %} <div class="title"> <a class="title1" href="student/">学生管理</a> <a class="title1" href="tercher/">教师管理</a> <a class="title1" href="class1/">班级管理</a> </div> {% endblock %} {% block gongneng %} <div class="gongneng"> <a class="neirong" href="add/">添加</a> <a class="neirong" href="del/">删除</a> <a class="neirong" href="bianji/">编辑</a> </div> {% endblock %} <div>information</div> </body> </html>
{% extends 'index1.html' %}#必须在第一行,说明继承index1这个文件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> </body> </html>
在继承之后,可以对继承来的进行重写
需求2:
不是简单的重写,而是将模板文件中的标签拿来,自己再进行修改
{% block title %} {# {{ block.super }}#} <div>hello</div> {% endblock %} </body> </html> 如果不这样,则会直接将模板的标签覆盖

浙公网安备 33010602011771号