forked from looly/python-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
10 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ | |
|
||
{% for index,element in enumerate(info) %} | ||
<p>info[{{index}}] is {{element}} | ||
{\% end %} | ||
{% end %} | ||
|
||
特别提醒注意的是,语句要用`{% end %}`来结尾。在循环体中,用`{{ element }}`方式使用序列的元素。 | ||
|
||
|
@@ -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> | ||
|
||
|
@@ -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> | ||
|
@@ -154,3 +154,5 @@ index.py的代码不变,只修改模板index.html的代码,重点理解模 | |
看官发现了吗?我用`{% set var="python-tornado" %}`的方式,将一个字符串赋给了变量`var`,在下面的代码中,就直接引用这个变量了。这样就是实现了模板中变量的使用。 | ||
|
||
Tornado的模板真的功能不少呢。不过远非这些,后面还有。敬请等待。 | ||
|
||
[首页](./index) | [上一讲:使用表单和模板](./311.md) |