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

后端 未结 5 1382
爱一瞬间的悲伤
爱一瞬间的悲伤 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:07

    The alternative to using relative path from the settings.py file, is for each developer to have their own settings.py.

    # settings.py
    TEMPLATE_DIRS = (
        'c:\django\templates\',
    )
    
    # dev-x-settings.py
    import settings
    TEMPLATE_DIRS = (
        'd:\dev\django\project\templates\'
    )
    

    The dev-x-settings.py imports all the settings from the base file, and changes the bits and pieces they need to. Also very handy for maintaining a local sqlite database and the like.

    We usually set out our settings as:

    /settings/
        __init__.py
        production.py
        staging.py
        test.py
        dev-x.py
        dev-y.py
    

    Then all you need to worry about is running the server and passing it the correct settings.py file.

提交回复
热议问题