Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Apr 4, 2015
1 parent 7dd9afa commit 21a5f58
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions 300/312.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

{% for index,element in enumerate(info) %}
<p>info[{{index}}] is {{element}}
{\% end %}
{% end %}

特别提醒注意的是,语句要用`{% end %}`来结尾。在循环体中,用`{{ element }}`方式使用序列的元素。

Expand All @@ -96,18 +96,18 @@ index.py的代码不变,只修改模板index.html的代码,重点理解模
<p>I will print the elements of this list in order.</p>
{% for element in info %}
<p>{{element}}</p>
{\% end %}
{% end %}
<br>
{% for index,element in enumerate(info) %}
<p>info[{{index}}] is {{element}}
{% if element == "python" %} <!-- 增加了一个判断语句 -->
<p> <b>I love this language--{{element}}</b></p>
{\% end %}
{\% end %}
{% end %}
{% end %}

{% if "[email protected]" in info %} <!-- 还是判断一下 -->
<p><b>A Ha, this the python lesson of LaoQi, It is good! His email is {{info[2]}}</b></p>
{\% end %}
{% end %}
</body>
</html>

Expand All @@ -129,18 +129,18 @@ index.py的代码不变,只修改模板index.html的代码,重点理解模
<p>I will print the elements of this list in order.</p>
{% for element in info %}
<p>{{element}}</p>
{\% end %}
{% end %}
<br>
{% for index,element in enumerate(info) %}
<p>info[{{index}}] is {{element}}
{% if element == "python" %}
<p> <b>I love this language--{{element}}</b></p>
{% end %}
{\% end %}
{% end %}

{% if "[email protected]" in info %}
<p><b>A Ha, this the python lesson of LaoQi, It is good! His email is {{info[2]}}</b></p>
{\% end %}
{% end %}
<h2>Next, I set "python-tornado"(a string) to a variable(var)</h2>
{% set var="python-tornado" %}
<p>Would you like {{var}}?</p>
Expand All @@ -154,3 +154,5 @@ index.py的代码不变,只修改模板index.html的代码,重点理解模
看官发现了吗?我用`{% set var="python-tornado" %}`的方式,将一个字符串赋给了变量`var`,在下面的代码中,就直接引用这个变量了。这样就是实现了模板中变量的使用。

Tornado的模板真的功能不少呢。不过远非这些,后面还有。敬请等待。

[首页](./index)&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;[上一讲:使用表单和模板](./311.md)

0 comments on commit 21a5f58

Please sign in to comment.