我需要用Python创建一个web服务器来列出一个目录的内容(文件和目录),但结果是只列出了文件,在我做的测试中,我列出了“/etc”,但问题是它没有显示/etc中存在的目录,只是几个/etc,然后它正确地列出了文件,有人能帮我吗??你知道吗
import web
import os
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, path):
path = '/etc/'+path
lista = '<html> <body>'
caminhos = [os.path.join(path, nome) for nome in os.listdir(path)]
for nome in caminhos:
lista = lista+path+'<br>'
arquivos = [arq for arq in caminhos if os.path.isfile(arq)]
for arq in arquivos:
lista = lista+arq+ '<br>'
lista = lista+'</body> </html>'
return lista
if __name__ == "__main__":
app.run()
目前没有回答
相关问题 更多 >
编程相关推荐