1.Django的模板系统
render_to_response
import django.shortcuts.render_to_response render_to_response的第一个参数必须是模板.如果给定第二个参数,第二个参数必须是为该模板创建Context时所用的字典;如果不提供第二个参数,render_to_response使用一个空字典.render_to_response返回一个HttpResponse对象.render_to_response的第二个参数可以用locals()代替,locals()返回所有局部变量的变量名和值的映射,包括request
get_template使用子目录,因为render_to_response只是对get_template的简单封装,所以render_to_response中也可以使用子目录.
2.include模板标签
当在很多文件中需要同一个模板文件的时候,可以考虑用include模板标签:{% include %}.该标签允许在模板中包含其他模板的内容.标签的参数是所要包含的模板的名称,可以是一个变量,也可以是单/双引号硬编码的字符串.
3.模板继承
本质上来说,模板继承就是先构造一个基础框架模板,而后在其子模板中对其它所包含的站点公用部分和定义进行重载