python腳本框架webpy模板控制結(jié)構(gòu)
控制結(jié)構(gòu)就是for,while,if-else,if-elif,while…else,在web.py中其實(shí)和我們以前學(xué)過的一樣,操作基本是相同的,但是里面還是有一些不同!
for
$for row in range(10):
第$row行
$def with(funs)
$for row in funs:
第$row行
這里一定要記住funs不要添加$
如果funs是list,那$ros具體list的一些屬性,在while中你可以看到
while
$while funs:
$funs.pop()
funs是list,具體pop屬性
if-else
$for row in range(10):
$if row==2:
我是2
$elif row==3:
我是3
$else:
$row
實(shí)例
index.html中的內(nèi)容
$def with(fun_name,funs)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>web參數(shù)模板</title>
</head>
<body>
<h2>我的名字:range函數(shù)的使用</h2>
$for row in range(10):
第$row行
<h2>我的名字:$fun_name</h2>
$# 注釋
$for row in funs:
第$row行
<h2>我的名字:while循環(huán)</h2>
$while funs:
$funs.pop()
<br/>
<h2>我的名字:if-else</h2>
$for row in range(10):
$if row==2:
我是2
$elif row==4:
我是4
$else:
$row
</body>
</html>
Python中的內(nèi)容:
#coding:utf-8
import web
urls=('/','Index',)
render =web.template.render('html/')
class Index:
def funA(self):
mylist=['1','2','3','4','5']
return mylist
def GET(self):
web.header('Content-Type','text/html;charset=UTF-8')
return render.myindex('for循環(huán)',[1,2,3,4,5,6,7,8,9,10])
app=web.application(urls,globals())
if __name__ == '__main__':
app.run()
結(jié)果:

以上就是python腳本框架webpy模板控制結(jié)構(gòu)的詳細(xì)內(nèi)容,更多關(guān)于webpy框架模板控制結(jié)構(gòu)的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
對python中大文件的導(dǎo)入與導(dǎo)出方法詳解
今天小編就為大家分享一篇對python中大文件的導(dǎo)入與導(dǎo)出方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
python中kmeans聚類實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了python中kmeans聚類的實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02
pytest下的pytest.ini文件的配置項(xiàng)
這篇文章主要給大家介紹了pytest下的pytest.ini文件的配置項(xiàng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧,2017-10-10

