没有此类资源 404 错误

G-C*_*der 1 html python twisted.web

我想运行 index.html。所以当我输入 localhost:8080 然后 index.html 应该在浏览器中执行。但它没有提供这样的资源。我正在指定 index.html 的整个路径。请帮帮我。?

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

resource = File('/home/venky/python/twistedPython/index.html')
factory = Site(resource)
reactor.listenTCP(8000, factory)
reactor.run()
Run Code Online (Sandbox Code Playgroud)

Wil*_*ton 5

根据此支持票,答案是bytes()在调用时使用对象putChild()。在原帖中,尝试:

resource = File(b'/home/venky/python/twistedPython/index.html')

在第一个答案中,请尝试:

resource = File(b'/home/venky/python/twistedPython/index.html') resource.putChild(b'', resource)