【问题标题】:bottle template not found ( Error 500 )找不到瓶子模板(错误 500)
【发布时间】:2014-01-25 22:25:06
【问题描述】:

我打算制作文件管理系统,但奇怪的问题是,当我应用返回目录内容的函数时,它会引发错误!

这是我返回目录内容的函数(在我的机器上 100% 工作)

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

这里是来自文件管理系统的代码

@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")

它会引发一个错误,上面写着:Template 'static/templates/TCP/FileMgr' not found. 但是当我评论 cont=GET_Contents(filepath)#just calling the function and ignore result 时,它工作正常!

【问题讨论】:

    标签: python python-2.7 template-engine bottle


    【解决方案1】:

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

    您可以轻松列出目录而无需更改工作目录:

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

    【讨论】:

    • 先生……你真棒xD
    猜你喜欢
    • 2016-01-28
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 2016-12-18
    • 1970-01-01
    相关资源
    最近更新 更多