shichen2014 通过本文主要向大家介绍了python twisted,python twisted下载,python twisted安装,twisted python3.5,twisted python3等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了Python基于twisted实现简单的web服务器,分享给大家供大家参考。具体方法如下:
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()
</div>
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,看到效果如下图所示:

希望本文所述对大家的Python程序设计有所帮助
</div>您可能想查找下面的文章:
- Python 基于Twisted框架的文件夹网络传输源码
- 剖析Python的Twisted框架的核心特性
- 实例解析Python的Twisted框架中Deferred对象的用法
- 详解Python的Twisted框架中reactor事件管理器的用法
- 使用Python的Twisted框架编写非阻塞程序的代码示例
- Python的Twisted框架中使用Deferred对象来管理回调函数
- 使用Python的Twisted框架构建非阻塞下载程序的实例教程
- Python的Twisted框架上手前所必须了解的异步编程思想
- 使用Python的Treq on Twisted来进行HTTP压力测试
- 利用Python的Twisted框架实现webshell密码扫描器的教程

