安装web.py
mac安装直接在终端中输入 一下代码
sudo pip install web.py
安装成功
Successfully installed web.py-0.38
如图
web.py测试
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
运行结果 如下:
web.py完整web
main.py
#coding=utf-8
import web
#url 匹配 带组的URL 映射到hello 方法
urls = (
'/index', 'index',
'/blog/\d+', 'blog',
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
return open(r'hell.html','r').read()
class index:
def GET(self):
return 'index mothod'
class blog:
def GET(self):
return 'blog method'
def POST(self):
return 'blog post mothod'
if __name__ == "__main__":
app.run()
hell.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我是标题</title>
</head>
<body>
<h1>我是网页</h1>
</body>
</html>