九、Django学习之templates模板标签

一、Django模板标签

1.if模板

{% if condition1  %}
    ... display 1
{% elif condition12 %}
    ... display 2
{% else %}
 
  ... display 3
{% endif %}

---------------------------------------------------
{% if a == 10 %}
    <h1>a10 == {{ a }}</h1>
{% elif a == 20 %}
    <h1>a20 == {{ a }}</h1>
{% endif %}

2.for模板

{% for foo in lsit %}

    <li>foo == {{ foo }}</li>
{% endfor %}
------------------------------------------------------
{% for foo in c %}

    <h1>foo == {{ foo }}</h1>
{% endfor %}

猜你喜欢

转载自www.cnblogs.com/chushujin/p/12450355.html