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()
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()
相关文章推荐
- python脚本生成exe文件
- python 编码问题记录
- 11个可能不知道的Python库
- Python爬虫简单笔记
- python装饰器和偏函数联合运用碰到的问题
- Python中的注释写法
- 20151007kaggle Titanic心得.md
- Win8系统 Python安装 - 入门
- Python入门之中文乱码
- 文章标题
- python windows whl pip 安装 64 位
- 线性回归中的数学原理
- 【python】抄写爬淘宝已买到的宝贝的代码
- python数字,简单码一码~
- python mysql盲注小程序
- <PY>kNN
- python3爬虫之入门和正则表达式
- python3爬虫之入门和正则表达式
- python爬虫程序,由根目录一直爬各个网址
- 简洁之美 -约瑟夫环的python 解法