Proposal: using relative paths in tutorial for less fragile projects
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I was going through the Polls tutorial and I noticed that it uses hardcoded absolute paths in the mysite/settings.py file, for example in NAME (sqlite3 database) and TEMPLATE_DIR.
I feel uneasy about using absolute paths in this case, because I need to fix settings.py every time I move the project to a different path (e.g. checking it out from a repo to a new box). I searched around for relative path support and saw that the core devs were against it in this issue, perhaps because the mechanism would be too implicit.
I saw a snippet in a Django tips SO thread, something like:
import os PROJECT_DIR = os.path.abspath( os.path.join( os.path.dirname(__file__), '..' ) ) PROJ_DIR_LAMBDA = lambda filename: os.path.join(PROJECT_DIR, filename)
Would it make sense to add this to the tutorial (even if just as a side note) to encourage best practices from the start?