Reputation: 1498
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 !
Upvotes: 0
Views: 1339
Reputation: 1125048
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))
Upvotes: 2