Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#24922 closed Bug (fixed)

Templates: conflicting settings should emit a system check error

Reported by: Sergei Maertens Owned by: Sergei Maertens
Component: Core (System checks) Version: master
Severity: Normal Keywords: templates, system check
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Sergei Maertens)

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

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:

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.

Change History (7)

comment:1 Changed 5 years ago by Sergei Maertens

Owner: changed from nobody to Sergei Maertens
Status: newassigned

comment:2 Changed 5 years ago by Sergei Maertens

Description: modified (diff)

comment:3 Changed 5 years ago by Raphael Michel

Triage Stage: UnreviewedAccepted

comment:4 Changed 5 years ago by Sergei Maertens

Has patch: set

comment:5 Changed 5 years ago by Tim Graham

Patch needs improvement: set

Reviewed the PR.

comment:6 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In eaf4d8c:

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.

comment:7 Changed 5 years ago by Tim Graham <timograham@…>

In c19bc2d5:

Fixed tests from refs #24922 when run in reverse.

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