Django模板语言 The Django template language 模板中常用的语法规则 {最新版本的Django语法可能有改变,不支持的操作可能支持了.[HTML教程 - 基本元素/标签及属性]} Django变量Variables A variable outputs a value from the context, which is a dict-like objectmapping keys to values. Variables are surrounded by {{…
就像HTML或者Python,Django模板语言同样提供代码注释. 注释使用 {# #} : ? 1 {# This is a comment #} 注释的内容不会在模板渲染时输出. 用这种语法的注释不能跨越多行. 这个限制是为了提高模板解析的性能. 在下面这个模板中,输出结果和模板本身是 完全一样的(也就是说,注释标签并没有被解析为注释): ? 1 2 3 This is a {# this is not a comment #} test. 如果要实现多行注释,可以使用`` {% comm…
1.模板系统 1.语法 1.变量相关 {{ name}} ,{{ name|length}}, {{ name |default:"默认值"}} 2.逻辑相关 1.if判断 {% if a > b %} //{% if a in b%} {% endif %} {% if a > b %} {% else %} {% endif %} {% if a > b %} {% elif %} {% else %} {% endif %} 2.for循环 {% for i i…