座机 发表于 2017-5-4 12:31:06

python的web框架webpy(二)

  之前介绍了webpy,还写了一个自己的web程序,下面我们就来分析下代码。

# coding:utf-8
import web
urls=(
'/','index'
)
app=web.application(urls,globals())
class index:
def GET(self):
return 'hello webpy!'
if __name__=='__main__':
app.run()

import web #导入webpy的模块

#这里声明了路由规则,它是一个tuple,由url匹配规则和处理类组成
#url匹配规则是用正则表达式书写的
urls=(
'/','index' #所有匹配上/的url都交由index类来处理
)
#可以声明多条路由规则,每一条都是由url匹配规则和处理类组成
urls=(
'/','index',
'/user','user',
'/topic','topic'
)


#初始化webapp
app=web.application(urls,globals())

#处理类index,它需要实现GET或POST方法
#return 可以返回你的处理结果到用户浏览器
class index:
def GET(self):
return 'hello webpy!'

#启动webapp
if __name__=='__main__':
app.run()
页: [1]
查看完整版本: python的web框架webpy(二)