使用web.py框架,实现简单的get和post请求:
py文件名:mytest.py
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
a = int(web.input().a)
b = int(web.input().b)
return a + b
def POST(self):
a = int(web.input().a)
b = int(web.input().b)
return a + b
if __name__ == "__main__":
app.run()
默认端口号为8080,可以使用命令行运行py文件,更改端口号,例如:
python mytest.py 8888
将端口号改为8888,在浏览器中访问get请求,返回结果为: