You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tentest/doc/week4work3

21 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

要分析 Django 模板的继承、包含关系及与模板标签Tag的依赖并通过 UML 包图呈现,需从包结构和关系类型(泛化、依赖)两方面拆解:
1. 核心概念与关系类型
模板继承(泛化 Generalization子模板通过 {% extends %} 继承基础模板的整体结构(如页面骨架、公共区块)。
模板包含(依赖 Dependency模板通过 {% include %} 嵌入可复用的组件模板(如导航栏、侧边栏),属于 “使用” 关系。
模板与标签的依赖(依赖 Dependency模板使用 {% static %}、{% url %} 等模板标签时,依赖标签库提供的功能。
2. UML 包图设计
以 “博客园文章详情页” 的模板体系为例,设计包结构与关系:
1包结构
顶层包 Templates管理所有模板相关资源
子包 BaseTemplates存放基础模板定义页面通用骨架如 base.html
子包 ComponentTemplates存放组件模板可复用的局部模块如 header.html 导航栏、sidebar.html 侧边栏);
子包 ArticleTemplates存放业务模板文章详情等场景化模板如 article_detail.html
子包 TagLibrary存放模板标签库提供 static、url 等内置 / 自定义标签)。
2关系映射
1. 继承泛化ArticleTemplates::article_detail.html 继承 BaseTemplates::base.html子模板复用基础模板的整体结构
2. 包含依赖BaseTemplates::base.html 包含 ComponentTemplates::header.html嵌入导航栏和 ComponentTemplates::sidebar.html嵌入侧边栏
3. 模板与标签的依赖BaseTemplates::base.html引入静态 CSS/JS和 ArticleTemplates::article_detail.html生成页面链接都依赖 TagLibrary使用 static、url 等标签)。
4. 关系解释
泛化(继承):箭头从子模板 article_detail.html 指向父模板 base.html表示子模板复用父模板的结构如 <head>、公共导航、布局框架);
依赖(包含):虚线箭头从 base.html 指向 header.html/sidebar.html表示 base.html 通过 {% include %} 嵌入这些组件模板;
依赖标签虚线箭头从模板base.html/article_detail.html指向 TagLibrary表示模板通过 {% static %}/{% url %} 等标签依赖标签库的功能。