使用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()函数:
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()

评论(0)