web.py笔记模板1

http://webpy.org/docs/0.3/templetor.zh-cn

http://webpy.org/docs/0.3/templetor

 

中文版的排版乱掉了,看懂了大体意思后还是看英文版吧

 

不过,疑问

1 这是内置的模板系统,下面还有3种兼容的模板系统,总共4种?哪个好?

2 在模板文件里写这么多python代码,维护方便?有点像jsp的初级阶段啊,mvc精神呢?只是为了方便?

3 没找到内部模板系统的具体说明文件啊,api没找到啊,下面这里面的这些内置函数都是啥?

Some common builtin functions like rangeminmax etc. and boolean values True and False are made available to all the templates.

 

$def $var $code的东西很有意思,还能像下面这样调用别的py文件的结果。。。

 

 

import web
import markdown

globals = {'markdown': markdown.markdown}
render = web.template.render('templates', globals=globals)
 

 

使用站点模板

http://webpy.org/cookbook/layout_template.zh-cn

 

根据以上这个url,做个练习

code.py

 

import web
urls = (
    '/', 'index'
)
render = web.template.render('templates/', base='layout')
class index:
    def GET(self):
        return render.index('mytitle')
if __name__ == "__main__":
    app = web.application(urls, globals())
   
    app.run()	
 

 

templates/layout.html

 

$def with (content)
<html>
<head>
    <title>$content.title</title>
</head>
<body>
$:content
</body>
</html>

 

templates/index.html  


$def with (title)
$var title: $title

<h3>Hello, world</h3>


$code:
    x = 1
    y = 2
    def plusxyz(z =3 ):
	   return x + y + z
	   
$plusxyz(4)
     	
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值