Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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 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.
)

My question is: How to deal with these absolute path when you're collaborating with a team? Say, if a team member has to modify the paths after getting the project from source control not only will this be error prone and time wasteful but it will also cause complications when this user has to commit a change made to settings.py. How can I avoid this?

like image 395
Raphael Avatar asked Dec 30 '10 11:12

Raphael


1 Answers

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.

like image 82
Blue Peppers Avatar answered Oct 17 '22 17:10

Blue Peppers