首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

web.py札记模板1

2012-09-14 
web.py笔记模板1http://webpy.org/docs/0.3/templetor.zh-cnhttp://webpy.org/docs/0.3/templetor?中文版

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?range,?min,?max?etc. and boolean values?True?and?False?are made available to all the templates.

?

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

?

?

import webimport markdownglobals = {'markdown': markdown.markdown}render = web.template.render('templates', globals=globals)
?

?

使用站点模板

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

?

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

code.py

?

import weburls = (    '/', '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)     
??

热点排行