questo codice è ottenere i template / blog1 / page.html in b.py:
path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'blog1/page.html'))
ma voglio ottenere la posizione della directory principale padre:
aParent
|--a
| |---b.py
| |---templates
| |--------blog1
| |-------page.html
|--templates
|--------blog1
|-------page.html
e come ottenere la posizione aParent
Grazie
aggiornamento:
è giusto:
dirname=os.path.dirname
path = os.path.join(dirname(dirname(__file__)), os.path.join('templates', 'blog1/page.html'))
o
path = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
os.path.join('templates', 'blog1/page.html')mi sembra strano. Stai mescolando le cose. O os.path.join('templates', 'blog1', 'page.html')oppure 'templates/blog1/page.html'. E molto più facile sarebbe os.path.abspath(os.path.join('templates', 'blog1', 'page.html'))allora
blog1oa? E dove si trova il tuo file attuale?