這段代碼是在b.py中獲取templates/blog1/page.html:
path = os.path.join(os.path.dirname(__file__), os.path .join("templates", "blog1/page.html"))
但我想獲取父目錄位置:
aParent |- -a | |---b.py | |---模板 | |--------博客1 | |-------page.html |--templates |--------blog1 |-------page.html
以及如何獲取父位置
謝謝
更新:
這是正確的:
dirname =os.path.dirname path = os.path.join(dirname(dirname(__file__)), os.path.join("templates", "blog1/page.html"))
或
path = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))