使用python写一个web

时间:2014-08-29 23:54:48   收藏:0   阅读:239

先编写hello.py,实现Web应用程序的WSGI处理函数:

# 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,负责启动WSGI服务器,加载application()函数:

bubuko.com,布布扣
from wsgiref.simple_server import make_server

from hello import application


httpd = make_server(‘‘, 8000, application)
print "Serving HTTP on port 8000..."

httpd.serve_forever()
View Code

bubuko.com,布布扣

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!