[Answer]-Why absolute paths in Django settings

1👍

When in doubt… check the documentation. According to the Django Docs,

◾It’s simplest to use absolute paths (i.e., directory paths that start at the root of the filesystem). If you want to be a bit more flexible and decoupled, though, you can take advantage of the fact that Django settings files are just Python code by constructing the contents of TEMPLATE_DIRS dynamically.

So to ensure portability while also ensuring the use of absolute paths, you generate the path dynamically as to avoid going down the awful road of hard-coded paths. As stated by @karthikr in his comment you can do something like,

TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
TEMPLATE_DIRS = (
    TEMPLATE_PATH,
)

where 'templates' is a directory within your project that contains your various html templates.

👤alacy

Leave a comment