您的位置:首页 > 其它

twisted 实现简单的web服务器

2012-04-07 15:02 459 查看
1. 新建htm文件夹,在这个文件夹中放入显示的网页文件

2. 在htm文件夹的同级目录下,建立web.py,web.py的内容为:

from twisted.web.resource import Resource
from twisted.web import server
from twisted.web import static
from twisted.internet import reactor

PORT = 1234

########################################################################
class ReStructed(Resource):
""""""

#----------------------------------------------------------------------
def __init__(self, filename, *a):
"""Constructor"""
self.rst = open(filename).read()
def render(self, request):
return self.rst

resource = static.File('htm/')
resource.processors = {'.html':ReStructed}
resource.indexNames = ['index.html']

reactor.listenTCP(PORT, server.Site(resource))
reactor.run()
3. 安装上twisted 下载地址为:http://twistedmatrix.com/trac/

安装上zope模块:http://old.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz/swreleasefile_view

5.在命令行中(windows系统)运行:python web.py

6.在浏览器中输入:127.0.0.1:1234,看到效果

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