[Django] #25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined

41 views
Skip to first unread message

Django

unread,
Jul 7, 2015, 3:45:16 PM7/7/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+--------------------
Reporter: danielr | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25079>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 7, 2015, 3:47:34 PM7/7/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
-------------------------------------+-------------------------------------
Reporter: danielr | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by danielr):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> 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`.

New description:

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:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:1>

Django

unread,
Jul 7, 2015, 7:57:47 PM7/7/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
-------------------------------------+-------------------------------------
Reporter: danielr | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:2>

Django

unread,
Jul 8, 2015, 11:11:12 AM7/8/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
-------------------------------------+-------------------------------------
Reporter: danielr | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by danielr):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:3>

Django

unread,
Jul 8, 2015, 11:34:02 AM7/8/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+------------------------------------

Reporter: danielr | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:4>

Django

unread,
Jul 13, 2015, 12:57:59 PM7/13/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+------------------------------------

Reporter: danielr | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:5>

Django

unread,
Jul 13, 2015, 5:51:19 PM7/13/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+------------------------------------
Reporter: danielr | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Template system | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"24620d71f2116da31abe6c9391f7bc807ac23c0b" 24620d7]:
{{{
#!CommitTicketReference repository=""
revision="24620d71f2116da31abe6c9391f7bc807ac23c0b"
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.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:6>

Django

unread,
Jul 13, 2015, 6:06:32 PM7/13/15
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+------------------------------------
Reporter: danielr | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Template system | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4cc0baa98e8a5bb8f2cf91539d141cbc30af6f61" 4cc0baa9]:
{{{
#!CommitTicketReference repository=""
revision="4cc0baa98e8a5bb8f2cf91539d141cbc30af6f61"
[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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:7>

Django

unread,
Jan 17, 2017, 10:09:53 PM1/17/17
to django-...@googlegroups.com
#25079: Warn if both TEMPLATES and TEMPLATE_DIRS are defined
--------------------------------------+------------------------------------
Reporter: Daniel Roseman | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Template system | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"98760ab0b2f1ce03234a5e6a52decd9f23d3994a" 98760ab]:
{{{
#!CommitTicketReference repository=""
revision="98760ab0b2f1ce03234a5e6a52decd9f23d3994a"
Refs #25079 -- Removed obsolete system check for TEMPLATE_* settings.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25079#comment:8>

Reply all
Reply to author
Forward
0 new messages