2014-01-25 86 views
0

我打算制作文件管理器系统,但它是奇怪的问题,当我应用返回目录内容的函数会引发错误!没有找到瓶子模板(错误500)

这里是我的函数返回目录中的内容从文件管理系统

@route("/TofePanel/FileManager/<filepath:path>") 
def FileMamager(filepath): 
    if request.get_cookie("__auth",secret="xxxxxxxx") is "xxxxxxxx": 
     cont=GET_Contents(filepath)#just calling the function and ignore result 
     return template("static/templates/TCP/FileMgr",PATH=filepath) 
    else: 
     redirect("/TofePanel/Login") 

它抛出一个错误,指出(在我的机器上工作的100%)

def GET_Contents(filepath): 
    os.chdir("files") 
    os.chdir(filepath) 
    contents=os.listdir(os.getcwd()) 
    return contents 

这里代码:Template 'static/templates/TCP/FileMgr' not found. 但是当我评论cont=GET_Contents(filepath)#just calling the function and ignore result它工作正常!

回答

2

不要更改工作目录;模板加载逻辑依赖于当前工作目录保持稳定。

您可以轻松地列出目录没有改变工作目录:

def GET_Contents(filepath): 
    return os.listdir(os.path.join('files', filepath)) 
+0

先生......你真棒的xD – Hamoudaq