Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am serving a local directory with Twisted http server as:

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()

The server serves the specified directory properly. But, when there is any index file (index, index.html) in a directory, then the server displays that index file, instead of serving the local directory. So, how do I tell Twisted server to ignore the index files and continue to serve the local directory?

twisted.web.static.File uses self.indexNames to determine which files are considered index files. You can override this value to change the behavior.

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()
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.