语法
- 变量 {{var}} , render _ template("index.html", title = 'Home', user = user)
-
控制
{% if title %} <title>{{title}} - microblog</title> {% else %} <title>Welcome to microblog</title> {% endif %}
-
循环
{% for post in posts %} <p>{{post.author.nickname}} says: <b>{{post.body}}</b></p> {% endfor %}
-
模板继承
- super(base.html):
其他内容 + {% block content %}{% endblock %} 如base 里面定义导航栏, 其他页面用 block content 扩展其他内容 - sub(index.html):
{% extends "base.html" %} {% block content %}Hi, {{user.nickname}}!
{% for post in posts %}{% endfor %}{{post.author.nickname}} says: {{post.body}}
- super(base.html):
this guy is lazy, nothing leave
comments powered by Disqus