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

使用python写一个web

2014-08-29 23:02 232 查看
先编写
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()


View Code

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