您的位置:首页 > 编程语言 > Python开发

python最简单的wsgi例子

2015-10-08 00:00 405 查看
摘要: Python内置了一个WSGI服务器,这个模块叫wsgiref,它是用纯Python编写的WSGI服务器的参考实现。所谓“参考实现”是指该实现完全符合WSGI标准,但是不考虑任何运行效率,仅供开发和测试使用。

from wsgiref.simple_server import make_server

def application(environ, start_response):

start_response('200 OK', [('Content-Type', 'text/html')])

body = '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:] or 'web')

return [body.encode('utf-8')]

httpd = make_server('',8001,application)

print('Serving HTTP on port 8001......')

httpd.serve_forever()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息