【Python】Learn Python the hard way, ex50 第一个网站

来源:互联网 发布:战斗机模型数据 编辑:程序博客网 时间:2024/04/29 18:41

利用lpthw.web框架实现"Hello World"网页版,代码如下:

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


0 0
原创粉丝点击