利用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>
本文介绍如何利用lpthw.web框架实现基本的HelloWorld网页应用,包括设置路由、创建视图类及运行应用。通过新建index.html模板文件进行文本渲染,展示最终的网页效果。
467

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



