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

前端 未结 14 1731
陌清茗
陌清茗 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

    from os.path import dirname, realpath, join
    join(dirname(realpath(dirname(__file__))), 'templates')
    

    Update:

    If you happen to "copy" settings.py through symlinking, @forivall's answer is better:

    ~user/
        project1/  
            mysite/
                settings.py
            templates/
                wrong.html
    
        project2/
            mysite/
                settings.py -> ~user/project1/settings.py
            templates/
                right.html
    

    The method above will 'see' wrong.html while @forivall's method will see right.html

    In the absense of symlinks the two answers are identical.

提交回复
热议问题