Question

i'm planing to make file manager system but it's weird problem that when i apply the function that return the directory content it raise an error !

here's my function that return directory content (works 100% in my machine)

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

and here code from the file manager system

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

it raise an error that says : Template 'static/templates/TCP/FileMgr' not found. but when i comment the cont=GET_Contents(filepath)#just calling the function and ignore result it works fine !

Was it helpful?

Solution

Don't change the working directory; the template loading logic relies on the current working directory remaining stable.

You can easily list a directory without changing the working directory:

def GET_Contents(filepath):
    return os.listdir(os.path.join('files', filepath))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top