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)文章!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。