There is a list, it is {{info}}
I will print the elements of this list in order.
{% for element in info %}{{element}}
{% end %}info[{{index}}] is {{element}} {% end %} 运行上面的程序: >>> python index.py 然后在浏览器地址栏中输入:`http://localhost:8000`,显示的页面如下图:  在上面的例子中,用如下样式,实现了模板中的for循环,这是在模板中常用到的,当然,从python程序中传过来的不一定是list类型数据,也可能是其它类型的序列数据。 {% for index,element in enumerate(info) %}
info[{{index}}] is {{element}}
{% end %}
特别提醒注意的是,语句要用`{% end %}`来结尾。在循环体中,用`{{ element }}`方式使用序列的元素。
##模板中的判断语句
除了循环之外,在模板中也可以有判断,在上面代码的基础上,改写一下,直接上代码,看官想必也能理解了。
index.py的代码不变,只修改模板index.html的代码,重点理解模板中的语句写法。
There is a list, it is {{info}}
I will print the elements of this list in order.
{% for element in info %}{{element}}
{% end %}info[{{index}}] is {{element}} {% if element == "python" %}
I love this language--{{element}}
{% end %} {% end %} {% if "qiwsir@gmail.com" in info %}A Ha, this the python lesson of LaoQi, It is good! His email is {{info[2]}}
{% end %} 上面的模板运行结果是下图样子,看官对比一下,是否能够理解呢?  ##模板中设置变量 废话不说,直接上例子,因为例子是非常直观的:There is a list, it is {{info}}
I will print the elements of this list in order.
{% for element in info %}{{element}}
{% end %}info[{{index}}] is {{element}} {% if element == "python" %}
I love this language--{{element}}
{% end %} {% end %} {% if "qiwsir@gmail.com" in info %}A Ha, this the python lesson of LaoQi, It is good! His email is {{info[2]}}
{% end %}Would you like {{var}}?
显示结果如下:  看官发现了吗?我用`{% set var="python-tornado" %}`的方式,将一个字符串赋给了变量`var`,在下面的代码中,就直接引用这个变量了。这样就是实现了模板中变量的使用。 Tornado的模板真的功能不少呢。不过远非这些,后面还有。敬请等待。 [首页](./index) | [上一讲:使用表单和模板](./311.md)