2011-08-07 73 views
4

這裏我有這個小例子片段,它只是不會從www dir服務index.html。代碼有什麼問題?扭曲的網絡服務器不提供文件

from twisted.internet import reactor 
from twisted.web import static, server, script 
import os 

DIRECTORY = os.getcwd()+"/www" 
root = static.File(DIRECTORY) 
root.indexNames = [ 'index.rpy', 'index.html' ] 
root.processors = { '.rpy': script.ResourceScript } 
site = server.Site(root) 
reactor.listenTCP(8090, site) 
reactor.run() 

我得到的只是'沒有這樣的資源'的信息。有沒有什麼辦法來設置日誌記錄或什麼來解決這個問題?

+0

你index.rpy需要包括'資源=。 ..'。較新版本的扭曲會給出更多信息錯誤消息。 – rob

回答

2

記錄可以通過添加這些行

from twisted.python import log 
import sys 
log.startLogging(sys.stdout) 
+0

謝謝。日誌記錄不顯示任何可能導致問題的解決方案:[HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [07/Aug/2011:17:21:33 +0000]「GET/HTTP/1.1」404 145「 - 「」Mozilla/5.0(Windows NT 6.1; WOW64; rv:5.0)Gecko/20100101 Firefox/5.0「 – marrat

0

當我得到這個錯誤設置,我不得不添加以下內容:

def getChild(self, name, request): 
    # for some reason this is needed for the root Resource to render at all 
    if name == b'': 
     return self 
    return super().getChild(name, request)