[Django] #24922: Templates: conflicting settings should emit a system check error

124 views
Skip to first unread message

Django

unread,
Jun 4, 2015, 10:32:03 AM6/4/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
--------------------------------------+------------------------------------
Reporter: sergei-maertens | Owner: nobody
Type: Bug | Status: new
Component: Core (System checks) | Version: master
Severity: Normal | Keywords: templates, system
| check
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
I discovered that specifying the templates settings as following, raises
an error when rendering the template:

{{{#!python
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
],
},
]
}}}

Error:
{{{
Traceback (most recent call last):
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/core/handlers/base.py", line 218, in get_response
response = self.handle_uncaught_exception(request, resolver,
sys.exc_info())
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/core/handlers/base.py", line 268, in
handle_uncaught_exception
return callback(request, **param_dict)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/views/defaults.py", line 42, in server_error
template = loader.get_template(template_name)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/loader.py", line 29, in get_template
engines = _engine_list(using)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/loader.py", line 144, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/utils.py", line 110, in all
return [self[alias] for alias in self]
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/utils.py", line 101, in __getitem__
engine = engine_cls(params)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/backends/django.py", line 24, in __init__
self.engine = Engine(self.dirs, self.app_dirs, **options)
File "/home/modelbrouw/.virtualenvs/staging/lib/python2.7/site-
packages/django/template/engine.py", line 36, in __init__
"app_dirs must not be set when loaders is defined.")
django.core.exceptions.ImproperlyConfigured: app_dirs must not be set when
loaders is defined.
}}}

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

Django

unread,
Jun 4, 2015, 10:32:19 AM6/4/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: templates, system | Triage Stage:
check | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: nobody => sergei-maertens
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Jun 4, 2015, 11:04:07 AM6/4/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: templates, system | Triage Stage:
check | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by sergei-maertens:

Old description:

New description:

I discovered that specifying the templates settings as following, raises
an error when rendering the template:

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

'DIRS': [os.path.join(BASE_DIR, 'templates')],


'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],

'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
],
},

},
]
}}}

urls.py:
{{{#!python
from django.conf.urls import include, url
from django.contrib import admin

from django.views.generic import TemplateView

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', TemplateView.as_view(template_name='test.html')),
]
}}}

Test template is just an empty file

Error:
{{{
Environment:


Request Method: GET
Request URL: http://localhost:8000/

Django Version: 1.8.2
Python Version: 3.4.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/core/handlers/base.py" in get_response
164. response = response.render()
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/response.py" in render
158. self.content = self.rendered_content
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/response.py" in rendered_content
133. template = self._resolve_template(self.template_name)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/response.py" in _resolve_template
88. new_template = self.resolve_template(template)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/response.py" in resolve_template
78. return loader.select_template(template,
using=self.using)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/loader.py" in select_template
57. engines = _engine_list(using)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/loader.py" in _engine_list
144. return engines.all() if using is None else [engines[using]]
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/utils.py" in all
110. return [self[alias] for alias in self]
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/utils.py" in <listcomp>
110. return [self[alias] for alias in self]
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/utils.py" in __getitem__
101. engine = engine_cls(params)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/backends/django.py" in __init__
24. self.engine = Engine(self.dirs, self.app_dirs, **options)
File "/home/bbt/coding/.virtualenvs/tpl_app_dirs/lib/python3.4/site-
packages/django/template/engine.py" in __init__
36. "app_dirs must not be set when loaders is
defined.")

Exception Type: ImproperlyConfigured at /
Exception Value: app_dirs must not be set when loaders is defined.
}}}

--

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

Django

unread,
Jun 4, 2015, 11:18:03 AM6/4/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: templates, system | Triage Stage: Accepted
check |

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

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

* stage: Unreviewed => Accepted


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

Django

unread,
Jun 4, 2015, 12:01:51 PM6/4/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: templates, system | Triage Stage: Accepted
check |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


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

Django

unread,
Jun 6, 2015, 1:58:07 PM6/6/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: templates, system | Triage Stage: Accepted
check |
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:

Reviewed the [https://github.com/django/django/pull/4773 PR].

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

Django

unread,
Jun 6, 2015, 7:41:40 PM6/6/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: closed

Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed

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

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


Comment:

In [changeset:"eaf4d8c0d85056c3481986fe092d5a8786bc4f26" eaf4d8c]:
{{{
#!CommitTicketReference repository=""
revision="eaf4d8c0d85056c3481986fe092d5a8786bc4f26"
Fixed #24922 -- Added system check for templates setting

If `'loaders'` is present in the `TEMPLATES` options together with
`APP_DIRS` set to `True`, the template engine raises an exception. This
conflict is now detected by the system check templates.E001.
}}}

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

Django

unread,
Jun 8, 2015, 8:18:23 AM6/8/15
to django-...@googlegroups.com
#24922: Templates: conflicting settings should emit a system check error
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sergei-
| maertens
Type: Bug | Status: closed
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed
Keywords: templates, system | Triage Stage: Accepted
check |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

In [changeset:"c19bc2d5d49f373b274772fa6cd936dfd05761e7" c19bc2d5]:
{{{
#!CommitTicketReference repository=""
revision="c19bc2d5d49f373b274772fa6cd936dfd05761e7"
Fixed tests from refs #24922 when run in reverse.
}}}

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

Reply all
Reply to author
Forward
0 new messages