Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#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 Daniel Roseman)

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.

PR: https://github.com/django/django/pull/4959

Change History (8)

comment:1 by Daniel Roseman, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

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.

comment:3 by Daniel Roseman, 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 Tim Graham, 9 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:5 by Tim Graham, 9 years ago

Patch needs improvement: unset

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 24620d7:

Fixed #25079 -- Added warning if both TEMPLATES and TEMPLATE_* settings are defined.

Django ignores the value of the TEMPLATE_* settings if TEMPLATES is also
set, which is confusing for users following older tutorials. This change
adds a system check that warns if any of the TEMPLATE_* settings have
changed from their defaults but the TEMPLATES dict is also non-empty.

Removed the TEMPLATE_DIRS from the test settings file; this was marked
for removal in 1.10 but no tests fail if it is removed now.

comment:7 by Tim Graham <timograham@…>, 9 years ago

In 4cc0baa9:

[1.8.x] Fixed #25079 -- Added warning if both TEMPLATES and TEMPLATE_* settings are defined.

Django ignores the value of the TEMPLATE_* settings if TEMPLATES is also
set, which is confusing for users following older tutorials. This change
adds a system check that warns if any of the TEMPLATE_* settings have
changed from their defaults but the TEMPLATES dict is also non-empty.

Removed the TEMPLATE_DIRS from the test settings file; this was marked
for removal in 1.10 but no tests fail if it is removed now.

Backport of 24620d71f2116da31abe6c9391f7bc807ac23c0b from master

comment:8 by Tim Graham <timograham@…>, 8 years ago

In 98760ab:

Refs #25079 -- Removed obsolete system check for TEMPLATE_* settings.

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