Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在twistd中使我的文件夹不可见/受限制的最佳方法是什么?_Python_Twisted - Fatal编程技术网

Python 在twistd中使我的文件夹不可见/受限制的最佳方法是什么?

Python 在twistd中使我的文件夹不可见/受限制的最佳方法是什么?,python,twisted,Python,Twisted,几天前,我试图学习python twisted…. 这就是我制作Web服务器的方法: from twisted.application import internet, service from twisted.web import static, server, script from twisted.web.resource import Resource import os class NotFound(Resource): isLeaf=True def render(

几天前,我试图学习python twisted….
这就是我制作Web服务器的方法:

from twisted.application import internet, service
from twisted.web import static, server, script
from twisted.web.resource import Resource
import os

class NotFound(Resource):
    isLeaf=True
    def render(self, request):
        return "Sorry... the page you're requesting is not found / forbidden"

class myStaticFile(static.File):
    def directoryListing(self):
        return self.childNotFound

#root=static.file(os.getcwd()+"/www")
root=myStaticFile(os.getcwd()+"/www")
root.indexNames=['index.py']
root.ignoreExt(".py")
root.processors = {'.py': script.ResourceScript}
root.childNotFound=NotFound()
application = service.Application('web')
sc = service.IServiceCollection(application) 
i = internet.TCPServer(8080, server.Site(root))#@UndefinedVariable
i.setServiceParent(sc)
在我的代码中,我为twisted.web.static.File创建了一个实例类,并
覆盖
目录列表

所以当用户尝试访问我的资源文件夹时(
http://localhost:8080/resource/
http://localhost:8080/resource/css
),它将返回一个未找到的页面。
但他仍然可以打开/阅读
http://localhost:8080/resource/css/style.css

它是有效的

我想知道的是。。这是正确的方法吗???
还有其他“完美”的方法吗?

我正在寻找一个禁用directoryListing的配置,比如
root.dirListing=False
。但是没有运气…

是的,这是一个合理的方法。您还可以使用
twisted.web.resource.NoResource
twisted.web.resource.forbidded
而不是定义自己的
NotFound