一个超级简单的python web程序

yipeiwu_com6年前Python基础

在MAC/LINUX环境下,执行vi hello.py命令,并输入以下代码

import web
import sys
 
urls = ("/Service/hello","hello")
app = web.application(urls,globals())
 
class hello:
    def GET(self):
        return 'Hello,world!';
if __name__=="__main__":
    app.run()

执行python hello.py 8080出现 

http://0.0.0.0:8080/
然后访问"http://localhost:8080/Service/Match"地址,返回结果为

Hello,world!


终端的结果为:

127.0.0.1:49400 - - [15/Aug/2014 17:57:26] "HTTP/1.1 GET /Service/Match" - 200 O

相关文章

python、PyTorch图像读取与numpy转换实例

Tensor转为numpy np.array(Tensor) numpy转换为Tensor torch.Tensor(numpy.darray) PIL.Image.Image转换成nu...

python通过opencv实现批量剪切图片

上一篇文章中,我们介绍了python实现图片处理和特征提取详解,这里我们再来看看Python通过OpenCV实现批量剪切图片,具体如下。 做图像处理需要大批量的修改图片尺寸来做训练样本,...

解决Python 中英文混输格式对齐的问题

Python中使用str.format进行格式化输出 format使用方法较多,这里只说明其在填充与对齐上的使用方法: 填充与对齐 填充常跟对齐一起使用 ^、<、>分别是居中...

老生常谈Python startswith()函数与endswith函数

函数:startswith() 作用:判断字符串是否以指定字符或子字符串开头 一、函数说明 语法:string.startswith(str, beg=0,end=len(string)...

Python判断两个文件是否相同与两个文本进行相同项筛选的方法

python判断两个文件是否相同 import hashlib def getHash(f): line=f.readline() hash=hashlib.md5()...