Template模版

1. myapp应用程序中,新建 ‘templates’ 文件夹;

2.settings.py中设置:

import os

TEMPLATE_DIRS = os.path.join(os.path.dirname(__file__),'templates')

3. 验证:

from django.template.loader import get_template

t = get_template("hello.html")
print (t)

  

4.templates的html继承

在1.html中使用block和endblock

<html>

<body>
<% block content %>
<p> Hello world! </p>
<% endblock %>
</body>

</html>

在2.html中使用extends继承

<% extends 1.html %>

<% block content %>
<% endblock %>

 

posted @ 2018-03-27 09:52  howardgoogle  阅读(84)  评论(0编辑  收藏  举报