When I configuration my TEMPLATE_DIRS in settings.py file, I use ever
"here" or
"here_cross" lambda function defined like this :
::
import os
here = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), x)
here_cross = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), *x)
I can configure TEMPLATE_DIRS or MEDIA_ROOT like this :
::
MEDIA_ROOT = ''
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.
here('myapp/templates'),
here_cross(('otherapp', 'templates')),
)
I suppose that this comment "Don't forget to use absolute paths, not
relative paths" is
relevant if I don't use "here" or "here_cross" function. If I don't
use it,
template paths are relative to current working directory and not to
"settings.py" file.
What do you think about this method (using here) ?
Why don't put "here" or/and "here_cross" in Django settings.py
skeleton ?
Sorry, I've some break line issue in my previous post.
This is my post cleaned.
Hi,
When I configuration my TEMPLATE_DIRS in settings.py file, I use ever
"here" or "here_cross" lambda function defined like this :
::
import os
here = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), x)
here_cross = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), *x)
I can configure TEMPLATE_DIRS or MEDIA_ROOT like this :
::
MEDIA_ROOT = ''
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.
here('myapp/templates'),
here_cross(('otherapp', 'templates')),
)
I suppose that this comment "Don't forget to use absolute paths, not
relative paths" is relevant if I don't use "here" or "here_cross"
function. If I don't use it, template paths are relative to current
working directory and not to "settings.py" file.
What do you think about this methode (using here) ?
Why don't put "here" or/and "here_cross" in Django settings.py
skeleton ?
> I can configure TEMPLATE_DIRS or MEDIA_ROOT like this :
> ::
> MEDIA_ROOT = ''
> 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. > here('myapp/templates'), > here_cross(('otherapp', 'templates')), > )
> I suppose that this comment "Don't forget to use absolute paths, not > relative paths" is relevant if I don't use "here" or "here_cross" > function. If I don't use it, template paths are relative to current > working directory and not to "settings.py" file.
> What do you think about this methode (using here) ? > Why don't put "here" or/and "here_cross" in Django settings.py > skeleton ?
If it works for you, it works. Personally I find lambdas a little difficult to read, and personally in this situation, I just put: os.path.normpath(os.path.join(os.path.dirname(__file__), 'otherapp', 'templates'))
inside of TEMPLATE_DIRS directly. I find that clearer to see what is happening, it is all in one line and still really simple.
I think it is a great idea. The lambda trick means I don't have to make any changes at all to switch between my development environment and production. A real life example from a current project: