Thus it was that the settings.py file used within Django has always puzzled me. You specify directories for where your templates go and you'll see the following
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.
)
I have no idea why this does this, and I'm not the only person but as I'm as thick as a whale omelette I am not going to argue with the developers. The real 'wtf' is why the comments lead people to put paths in that will break when used on the next developer's machine. I'm developing on linux in my home directory, we deploy onto linux into a different users directory, the other developers mostly use Macs which have a different directory structure for homes.
Anyway - enough. As the ticket comments for this 'fault' say. The solution is simple. settings.py is a python file so do something like this.
import os
root_path=os.path.realpath(os.curdir)
TEMPLATE_DIRS = (
"%s/legacy/templates" % root_path,
"%s/edi/templates" % root_path,
)
And your world will be a better place.
1 comments:
Heh, thanks Ian. I've recently started learning Django and when I first saw the templates config section in settings.py I made a mental note to find out how to avoid hard-coding paths. Looks like I need look no further :-)
Post a Comment