利用lpthw.web框架实现"Hello World"网页版,代码如下:
import web
urls = ('/', 'index')
app = web.application(urls, globals())
render = web.template.render('templates/')
class Index:
def GET(self):
greeting = 'Hello World'
return render.index(greeting = greeting)
if __name__ == '__main__':
app.run()
另外,在templates文件夹内建立index.html模板文件,渲染文本,最终输出入下图所示
index.html内容如下:
$def with (greeting)
<html>
<head>
<title>Gothons Of Planet Percal #25</title>
</head>
<body>
$if greeting:
I just wanted to say <em style='color: green; font-size:2em;'>$greeting
</em>.
$else:
<em>Hello</em>, world!
<body>
</html>