加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python web.py实现简单的get和post请求

发布时间:2020-12-17 17:07:02 所属栏目:Python 来源:网络整理
导读:使用web.py框架,实现简单的get和post请求: py文件名:mytest.py 1 import web 2 urls = ( 3 ' / ' , ' hello ' 4 ) 5 app = web.application(urls,globals()) 6 7 class hello: 8 def GET(self): 9 a = int(web.input().a) 10 b = int(web.input().b) 11 r

使用web.py框架,实现简单的get和post请求:

py文件名:mytest.py

 1 import web
 2 urls = (
 3      '/','hello'
 4 )
 5 app = web.application(urls,globals())
 6 
 7 class hello:
 8     def GET(self):
 9         a = int(web.input().a)
10         b = int(web.input().b)
11         return a + b
12 
13     def POST(self):
14         a = int(web.input().a)
15         b = int(web.input().b)
16         return a + b
17 
18 if __name__ == "__main__":
19     app.run()

?

默认端口号为8080,可以使用命令行运行py文件,更改端口号,例如:

python mytest.py 8888

将端口号改为8888,在浏览器中访问get请求,返回结果为:

?

?使用postman或jmeter访问post请求,返回结果为:

?

?

需要注意的是,每次代码更新后,都需要重新运行py文件

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读