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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With