Using Python's os.path, how do I go up one directory?

前端 未结 14 1798
陌清茗
陌清茗 2020-12-07 07:47

I recently upgrade Django from v1.3.1 to v1.4.

In my old settings.py I have

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname( __file_         


        
14条回答
  •  天涯浪人
    2020-12-07 08:14

    I think the easiest thing to do is just to reuse dirname() So you can call

    os.path.dirname(os.path.dirname( __file__ ))
    

    if you file is at /Users/hobbes3/Sites/mysite/templates/method.py

    This will return "/Users/hobbes3/Sites/mysite"

提交回复
热议问题