{{{
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.
* 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>
* 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>
* 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>
* owner: nobody => harrislapiroff
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25788#comment:4>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6954 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25788#comment:5>
* needs_better_patch: 0 => 1
Comment:
Some test failures need to be fixed.
--
Ticket URL: <https://code.djangoproject.com/ticket/25788#comment:6>
* 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>
* 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>
Comment (by jaap3):
Thanks Harris/Tim! Just one question, how does this impact #25791?
--
Ticket URL: <https://code.djangoproject.com/ticket/25788#comment:9>