Frage

I am new to turbogears and have an app that I am creating with multiple directories under public/media/ballots. I need to see if a directory exists.

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"

I've tried multiple ways of defining the path: "/media/ballots/", "./media/ballots/", "media/ballots". But the os.path.exists(path) always returns false. I'm not sure how TG is accessing the public files.

War es hilfreich?

Lösung 2

I had to make the path="projectname/public/media/ballots/"

Andere Tipps

tg.config['paths']['static_files'] will give you the absolute path of the public directory. You can then use os.path.join to chain it to the path of your files relative to the public one.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top