Get absolute path of django app

后端 未结 6 2081
一整个雨季
一整个雨季 2021-02-03 20:09

I am writing a unit test that needs to access an image file that I put in \"fixtures\" directory right under my django app directory. I want to open up this image file in my tes

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 20:44

    Keep in mind that appname.__path__ is a list:

    import appname
    APP_ROOT = os.path.abspath(appname.__path__[0])
    file_path = os.path.join(APP_ROOT, "some_file.txt")
    
    

提交回复
热议问题