ce code est récupéré les templates / blog1 / page.html dans b.py:
path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'blog1/page.html'))
mais je veux obtenir l'emplacement du répertoire parent:
aParent
|--a
| |---b.py
| |---templates
| |--------blog1
| |-------page.html
|--templates
|--------blog1
|-------page.html
et comment obtenir l'emplacement aParent
Merci
actualisé:
c'est juste:
dirname=os.path.dirname
path = os.path.join(dirname(dirname(__file__)), os.path.join('templates', 'blog1/page.html'))
ou
path = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
os.path.join('templates', 'blog1/page.html')me semble étrange. Vous mélangez les choses. Soit os.path.join('templates', 'blog1', 'page.html')ou 'templates/blog1/page.html'. Et beaucoup plus facile serait os.path.abspath(os.path.join('templates', 'blog1', 'page.html'))alors
blog1oua? Et où se trouve votre fichier actuel?