参考:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386832689740b04430a98f614b6da89da2157ea3efe2000

代码:

hello.py

 #!/usr/bin/python
# coding: utf-8 # hello.py
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:] or 'web')

server.py

 #!/usr/bin/python
# coding: utf-8 # server.py
from wsgiref.simple_server import make_server
from hello import application # create server, ip is empty, port is 8000, handle function is application
httpd = make_server('', 8000, application)
print "Serving HTTP on port 8000..."
# start listen http request
httpd.serve_forever()

使用了模块wsgiref。它实现了wsgi接口,我们只需要定一个wsgi处理函数来处理得到的请求就可以了。

用python来实现这些看似很复杂的实例程序,非常简单,这都得益于python强大的库。

最新文章

  1. Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用
  2. iOS之开发中一些相关的路径以及获取路径的方法
  3. 一鼓作气 博客--第八篇 note8
  4. iniutils for Golang
  5. NSJSONSerialization 组json字符串
  6. Python解决八皇后问题
  7. JDK AIO编程
  8. 解决编译错误: 非法字符: &#39;\ufeff&#39; 解决方案|错误: 需要class, interface或enum
  9. IOS开发--常用工具类收集整理(Objective-C)(持续更新)
  10. 如何在Linux下创建与解压zip, tar, tar.gz和tar.bz2文件
  11. IOS高级开发 runtime(一)
  12. C# 枚举 字符串 转换
  13. C#量转换为汉字表达
  14. 文件:一个任务 - 零基础入门学习Python029
  15. 2014联合三所学校 (HDU 4888 HDU 4891 HDU 4893)
  16. 区间的连续段~ST表(模板题)
  17. archlinux 装完系统连接 wifi 网络
  18. CentOS 6.5 x64下安装宝塔面板、阿里安骑士
  19. Eigen子矩阵操作
  20. U3D Time类

热门文章

  1. 【权值分块】bzoj1588 [HNOI2002]营业额统计
  2. SciPy中两个模块:io 和misc
  3. java调用windows的wmi获取设备性能数据
  4. 使用Arraylist产生不重复的随机数
  5. php获取两个日期之间的所有日期
  6. linux-磁盘目录使用情况-df/du
  7. Android之startActivityForResult
  8. 打算安装个Ubuntu双系统,遇到了些基本概念问题(主分区、活动分区、扩展分区、逻辑分区)
  9. mormot 直接使用UNIDAC引擎操作数据库
  10. Solr报错Index locked for write for core &#39;***&#39;. Solr now longer supports forceful unlocking via &#39;unlockOnStartup&#39;