网络编程
位置:首页>> 网络编程>> Python编程>> python脚本框架webpy模板控制结构

python脚本框架webpy模板控制结构

作者:枫少文  发布时间:2023-07-08 23:45:34 

标签:web.py,模板,控制结构

控制结构就是for,whileif-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中你可以看到

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中的内容


$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模板控制结构

来源:https://blog.csdn.net/guofeng93/article/details/54095259

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com