我是turbogears的新手,我有一个应用程序,我正在公共/媒体/选票下创建多个目录.我需要查看目录是否存在.
path = "public/media/ballots/" + x['directoryName']
#return path
if os.path.exists(path):
listing = os.listdir(path)
i=0
for infile in listing:
#find path for ballot1, ballot2, etc from files in directory
i +=1
Ballot = "Ballot" +str(i)
x['Ballot']= infile
return x
else:
return "false"
Run Code Online (Sandbox Code Playgroud)
我尝试了多种方法来定义路径:"/ media/ballots /","./ media/ballots /","media/ballots".但是os.path.exists(path)总是返回false.我不确定TG是如何访问公共文件的.
tg.config ['paths'] ['static_files']将为您提供公共目录的绝对路径.然后,您可以使用os.path.join将其链接到文件相对于公共文件的路径.
| 归档时间: |
|
| 查看次数: |
132 次 |
| 最近记录: |