这篇教程python脚本框架webpy模板控制结构写得很实用,希望能帮到您。 控制结构就是for ,while ,if-else ,if-elif ,while…else ,在web.py中其实和我们以前学过的一样,操作基本是相同的,但是里面还是有一些不同!
for$for row in range(10): 第$row行$def with(funs)$for row in funs: 第$row行 这里一定要记住funs不要添加$ 如果funs是list,那$ros具体list的一些属性,在while中你可以看到
whilefuns是list,具体pop属性
if-else$for row in range(10): $if row==2: 我是2 $elif row==3: 我是3 $else: $row
实例index.html中的内容 $def with(fun_name,funs)<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>web参数模板</title> </head> <body> <h2>我的名字:range函数的使用</h2> $for row in range(10): 第$row行 <h2>我的名字:$fun_name</h2> $# 注释 $for row in funs: 第$row行 <h2>我的名字:while循环</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中的内容: #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循环',[1,2,3,4,5,6,7,8,9,10]) app=web.application(urls,globals()) if __name__ == '__main__': app.run() 结果: 
以上就是python脚本框架webpy模板控制结构的详细内容,更多关于webpy框架模板控制结构的资料请关注51zixue.net其它相关文章! python脚本框架webpy的url映射详解 python脚本框架webpy模板赋值实现 |