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 range, min, max 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)

被折叠的 条评论
为什么被折叠?



