Get absolute path of django app

后端 未结 6 2021
一整个雨季
一整个雨季 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:51

    Normally, this is what I add in my settings.py file so I can reference the project root.

    import os.path
    
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    

    This method will get the directory of any python file.

提交回复
热议问题