#25079 closed Cleanup/optimization (fixed)
Warn if both TEMPLATES and TEMPLATE_DIRS are defined
Reported by: | Daniel Roseman | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Since the addition of the pluggable template backends, the TEMPLATE_DIRS
setting has been deprecated in favour of the TEMPLATES
list of dicts. If TEMPLATES
is not defined, it will be constructed using the value of TEMPLATE_DIRS
.
However, TEMPLATES
is created automatically by the default project template; and in this case Django does not use the value in TEMPLATE_DIRS
. This means that users following pre-1.8 tutorials (for example, the very popular Tango with Django) will be instructed to add TEMPLATE_DIRS
to a settings file that ignores that value, and then will be surprised that their templates are not found. This has hit quite a few users on StackOverflow, for example:
http://stackoverflow.com/questions/31108314/templatedoesnotexist-error-in-django/31109213
http://stackoverflow.com/questions/30844500/django-templatedoesnotexist-error-on-windows-machine
http://stackoverflow.com/questions/30740700/django-templatedoesnotexist-at-home-html
http://stackoverflow.com/questions/26176267/django-template-loader-cant-find-template/30588425#30588425
and so on.
Django should explicitly warn in this case, telling users to move their directories settings to TEMPLATES
.
Change History (8)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
I hadn't considered the other template settings - DIRS
is the one that people need to modify in order to get their templates loading at all, so is the biggest concern. If you think it's valuable though I can loop through all the TEMPLATE_*
settings and raise a warning if they are present.
For the compatibility issue, that's really why it's a warning rather than an ImproperlyConfigured exception; warnings are easily silenced or even just ignored.
comment:4 by , 9 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:5 by , 9 years ago
Patch needs improvement: | unset |
---|
Is there a reason not to add similar warnings for all deprecated
TEMPLATE_
settings? I guess the main problem with this would be on projects that deliberately define both settings for compatibility with multiple versions of Django.