[Django] #25788: Enabling the cached template loader should be easier

12 views
Skip to first unread message

Django

unread,
Nov 20, 2015, 4:03:14 PM11/20/15
to django-...@googlegroups.com
#25788: Enabling the cached template loader should be easier
---------------------------------+--------------------
Reporter: jaap3 | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Currently enabling the cached template loader is a lot of effort, you'll
have to change your settings from something like this:

{{{
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True
}]
}}}

To this:

{{{
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'OPTIONS': {
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
],
},
}]
}}}

Making sure you don't forget to take out the `APP_DIRS` option, figuring
out what loaders to use and getting the nesting of tuples and lists just
right.

I propose adding an option the Django template engine called
`cache_templates` to simplify all of this. Making the second example look
more like this:

{{{
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True
'OPTIONS': {'cache_templates': DEBUG}
}]
}}}

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

Django

unread,
Nov 21, 2015, 8:57:15 AM11/21/15
to django-...@googlegroups.com
#25788: Enabling the cached template loader should be easier
---------------------------------+--------------------------------------

Reporter: jaap3 | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
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 timgraham):

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


Comment:

I don't find it to be a lot of effort to
[https://docs.djangoproject.com/en/1.8/ref/templates/api/#django.template.loaders.cached.Loader
copy/paste from the docs]. On the other hand, it takes a non-trivial
cognitive effort to maintain another option and teach users about what it
does. I forget the justification for `APP_DIRS` (which seems slightly
redundant) but I don't think adding more options like that is a good path
to go down.

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

Django

unread,
Nov 23, 2015, 12:07:21 PM11/23/15
to django-...@googlegroups.com
#25788: Enabling the cached template loader should be easier
---------------------------------+-----------------------------------------

Reporter: jaap3 | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Someday/Maybe

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Someday/Maybe


Comment:

[https://groups.google.com/d/topic/django-
developers/JMwJWTgtFfc/discussion django-developers discussion]

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

Django

unread,
Jan 11, 2016, 6:44:49 PM1/11/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
---------------------------------+------------------------------------

Reporter: jaap3 | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* has_patch: 1 => 0
* stage: Someday/Maybe => Accepted


Comment:

Aymeric suggested to enable the cached template loader by default when
`DEBUG = False` and no `‘loaders’` options is specified.

This is technically backwards-incompatible, but:
- people who don’t usually configure it will get a free performance boost
in production
- people who do will be able to simplify their configurations

Currently many projects have a variant of this awful pattern:
{{{
# settings/prod.py

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',

'OPTIONS': {
'loaders': [
('django.template.loaders.cached.Loader', [

'django.template.loaders.app_directories.Loader',
]),
],
},

},
]

# settings/dev.py

from .prod import *

TEMPLATES[0]['OPTIONS'].update({
'loaders': [
'django.template.loaders.app_directories.Loader',
],
})
}}}
His suggestion makes it possible to remove the configuration of
`‘loaders’` and to rely only on `DIRS` and `APP_DIRS` instead.

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

Django

unread,
Jul 21, 2016, 10:12:50 AM7/21/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by harrislapiroff):

* owner: nobody => harrislapiroff
* status: new => assigned


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

Django

unread,
Jul 21, 2016, 4:30:36 PM7/21/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: assigned
Component: Template system | Version: master
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 harrislapiroff):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6954 PR]

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

Django

unread,
Jul 22, 2016, 9:33:48 AM7/22/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: assigned
Component: Template system | Version: master
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


Comment:

Some test failures need to be fixed.

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

Django

unread,
Sep 2, 2016, 7:52:33 PM9/2/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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
* stage: Accepted => Ready for checkin


Comment:

Fixed test failures in a new [https://github.com/django/django/pull/7204
PR].

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

Django

unread,
Sep 3, 2016, 9:06:53 AM9/3/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: closed

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

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"277fe2e8f2ee35cd389b079ce7691491bb5738ec" 277fe2e8]:
{{{
#!CommitTicketReference repository=""
revision="277fe2e8f2ee35cd389b079ce7691491bb5738ec"
Fixed #25788 -- Enabled the cached template loader if debug is False.
}}}

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

Django

unread,
Sep 5, 2016, 3:59:41 AM9/5/16
to django-...@googlegroups.com
#25788: Enable the cached template loader when DEBUG=False if no loaders are
explicitly configured
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner:
| harrislapiroff
Type: New feature | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jaap3):

Thanks Harris/Tim! Just one question, how does this impact #25791?

--
Ticket URL: <https://code.djangoproject.com/ticket/25788#comment:9>

Reply all
Reply to author
Forward
0 new messages