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的文件

<em>欢迎使用</em>

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值