webpy使用说明(一)

webpy使用说明(一)

webpy其实是html的一个翻译器,它将python语句翻译成html语句。
先来看一个简单的index.py。

import web,os

urls = ('/','index')

class index:
    def GET(self):        
        return 'Hello,World'

if __name__ == "__main__":
    app = web.application(urls,globals())    
    app.run()

当运行python index.py,用浏览器访问127.0.0.1:8080
就会显示出’Hello,World’

再来一个例子。webpy只是对一些常见的html语法进行了集合。但如果你要用,又没有集合的语法。那么就需要用的templates.

import web,os
urls = ('/','index')
render = web.template.render('templates/')

class index:
    def GET(self):        
        return render.index()


if __name__ == "__main__":
    app = web.application(urls,globals())    
    app.run()

templates文件夹下是一个index.html的文件

欢迎使用

当浏览器访问127.0.0.1:8080,get消息会把index.htm翻译成html,返回给浏览器。

你可能感兴趣的:(python)