Opened 11 years ago

Closed 11 years ago

#19410 closed Uncategorized (duplicate)

Proposal: using relative paths in tutorial for less fragile projects

Reported by: kristian.i.kolev@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)
'NAME': PROJ_DIR_LAMBDA('sqlite3.db'),

Would it make sense to add this to the tutorial (even if just as a side note) to encourage best practices from the start?

Change History (1)

comment:1 by Aymeric Augustin, 11 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #16504.

Note: See TracTickets for help on using tickets.
Back to Top