标签:
WSGI:Web Server Gateway Interface
只要求Web开发者实现一个函数,就可以响应HTTP请求。
# hello.py def application(environ, start_response): start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)]) return [b‘<h1>Hello, web!</h1>‘]
# server.py from wsgiref.simple_server import make_server from hello import application # 创建一个服务器,IP地址为空,端口是8000,处理函数是application: httpd = make_server(‘‘, 8000, application) print(‘Serving HTTP on port 8000...‘)
# 开始监听HTTP请求: httpd.serve_forever()
运行server.py,浏览器中输入IP:8000即可访问
标签:
原文地址:http://www.cnblogs.com/roronoa-sqd/p/4911693.html