python腳本框架webpy模板控制結(jié)構(gòu)
控制結(jié)構(gòu)就是for,while,if-else,if-elif,while…else,在web.py中其實和我們以前學(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
實例
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)的詳細內(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

