Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25061 closed Bug (invalid)

Default template loader wrong in docs OR default loader not working properly

Reported by: Mike Lissner Owned by: nobody
Component: Template system Version: 1.8
Severity: Normal Keywords: loader, templates, defaults
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Not sure if the docs are correct or if the functionality is incorrect. In any case, the docs say that in Django 1.8, the default template loaders are:

('django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader')

The error I ran into was that when I had the TEMPLATES variable set, Django could not find the templates from the debug toolbar, which made me think that the app_directories loader wasn't working.

I did three tests:

First, I added the above tuple to the TEMPLATES directory to see if the default wasn't being set correctly. When I added the values above, suddenly the template was found successfully.

Second, I created a brand new project in a brand new virtualenv. In the env I installed django_debug_toolbar and django 1.8.2. I then added debug_toolbar to the installed apps, and tested if runserver could find the templates it needed to. Sure enough, this worked.

Third, when that worked, I noticed that the default settings for Django 1.8.2 still use the TEMPLATE_ format. This seems odd (perhaps an indicator that my system wasn't clean?) but I swapped the settings over to use the TEMPLATES variable instead. Again, when 'loaders' is unset, the template can't be found, but when it is set to the supposed default value, things work fine.

Change History (3)

comment:1 by Tim Graham, 9 years ago

Which docs are you referring to regarding the template loaders defaults? Is it from the TEMPLATE_LOADERS setting? If so, I think the confusion is that once you define the TEMPLATES setting, the old TEMPLATE_ settings are ignored.

comment:2 by Carl Meyer, 9 years ago

Resolution: invalid
Status: newclosed

As best I can figure out, OP is either referring to what you linked, or to the mention of "the default value of TEMPLATE_LOADERS" in https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/#the-templates-settings

Both of those are referring to the default value of TEMPLATE_LOADERS pre-1.8. The default value of ['OPTIONS']['loaders'] for Django Template Language in 1.8 is more complex; it only includes the app_directories loader if you set APP_DIRS: True, as documented in the TEMPLATES setting docs: https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-TEMPLATES

I would assume the OP isn't setting APP_DIRS: True. It defaults to False, though the startproject default settings file sets it to True.

But it sounds like OP also has a polluted installation of 1.8 which is somehow still using an old project template. Django 1.8 startproject template definitely uses TEMPLATES, not TEMPLATE_*.

comment:3 by Mike Lissner, 9 years ago

Yeah, I think it's safe to close this off. I thought that the old TEMPLATE_* settings were mapped more or less directly to the new OPTIONS key...missed that it's {} by default.

End of day Friday. Apologies.

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