python3使用WSGI启动服务

WSGI是Web Server Gateway Interface的简称。它不是服务器,python模块,框架,API和任何种类的软件。它仅仅是一个服务器和应用间的接口规范。

from wsgiref.simple_server import make_server


def application(environ, start_response):

    start_response('200 OK', [('Content-Type', 'text/html')])   # 请求头信息

    return [b'<h1>hello world!</h1>']        # 返回body信息


a = 8080   # 设置端口

httpd = make_server('', a, application)
httpd.serve_forever()                    # 设置服务一直启动

运行文件后,在浏览器输入:localhost:8080(设置的端口号)即可访问到启动的服务

猜你喜欢

转载自www.cnblogs.com/wanxiaochao/p/11693652.html