Django - How to deal with the paths in settings.py on collaborative projects

后端 未结 5 1291
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 08:17

I have just started a feasibility study on Django for my company and I have noticed the need for absolute paths on settings.py:

TEMPLATE_DIRS = (
   # Put string         


        
5条回答
  •  清歌不尽
    2021-02-01 09:03

    import os.path
    
    #Get the absolute path of the settings.py file's directory
    PWD = os.path.dirname(os.path.realpath(__file__ )) 
    
    TEMPLATE_DIRS = (
        # Put strings here, like "/home/html/django_templates" or 
        # "C:/www/django/templates".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
    
        #Add Templates to the absolute directory
        os.path.join(PWD, "Templates") 
    )
    

    That's how I do relative imports. Note that is usually wise to have a separate localsettings.py file, or something similar.

提交回复
热议问题