python - 如何告诉 Twisted http 服务器忽略索引文件

标签 python twisted twisted.web

我正在使用 Twisted http 服务器提供本地目录:

from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor, endpoints

resource = File('./')
factory = Site(resource)
reactor.listenTCP(8888,factory)
reactor.run()

服务器正确地为指定的目录提供服务。但是,当目录中存在任何索引文件(index、index.html)时,服务器将显示该索引文件,而不是提供本地目录。 那么,如何告诉 Twisted 服务器忽略索引文件并继续为本地目录提供服务?

最佳答案

twisted.web.static.File 使用 self.indexNames 来确定哪些文件被视为索引文件。您可以覆盖此值以更改行为。

from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor, endpoints

resource = File('./')
resource.indexNames = []
factory = Site(resource)
reactor.listenTCP(8888,factory)
reactor.run()

关于python - 如何告诉 Twisted http 服务器忽略索引文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75319769/

相关文章:

python - 使用 AWS 创建 Alexa 对话技能

python - python 中的最长匹配

python - 使用twistd运行高速公路应用程序

python - 为什么 Twisted Transports 没有接收数据的方法?

python - python扭曲中的循环调用不起作用

python - 将列表转换为命名元组

python - 无法用conda卸载keras

python - Scrapy 下载错误和 remove_request 错误

python - 使用 Twisted 进行基本 HTTP 解析

python : Clear the buffer in Twisted Transport write