bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 423 forks source link

For Django 1.10.6 ImportError: cannot import name 'TemplateDoesNotExist' #456

Closed uadnan closed 7 years ago

uadnan commented 7 years ago

Django Version: 1.10.6 Python Version: 3.5.2

Settings:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                "django.contrib.messages.context_processors.messages",
                "django.template.context_processors.request"
            ],
            'loaders': [
                (
                    'tenant_schemas.template_loaders.CachedLoader', (
                        'tenant_schemas.template_loaders.FilesystemLoader',
                        'django.template.loaders.filesystem.Loader',
                        'django.template.loaders.app_directories.Loader'
                    )
                )
            ]
        }
    }
]

Error traceback:

Traceback (most recent call last):
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = get_response(request)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
    response = response.render()
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/response.py", line 109, in render
    self.content = self.rendered_content
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/response.py", line 84, in rendered_content
    template = self.resolve_template(self.template_name)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/response.py", line 66, in resolve_template
    return select_template(template, using=self.using)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/loader.py", line 48, in select_template
    return engine.get_template(template_name)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/backends/django.py", line 39, in get_template
    return Template(self.engine.get_template(template_name), self)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/engine.py", line 160, in get_template
    template, origin = self.find_template(template_name)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/engine.py", line 130, in find_template
    for loader in self.template_loaders:
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/engine.py", line 104, in template_loaders
    return self.get_template_loaders(self.loaders)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/engine.py", line 109, in get_template_loaders
    loader = self.find_template_loader(template_loader)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/template/engine.py", line 122, in find_template_loader
    loader_class = import_string(loader)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/adnan/.virtualenvs/sixsents/lib/python3.5/site-packages/tenant_schemas/template_loaders.py", line 9, in <module>
    from django.template.base import TemplateDoesNotExist, Template
ImportError: cannot import name 'TemplateDoesNotExist'
uadnan commented 7 years ago

Seems like In Django 1.10 TemplateDoesNotExist is moved to django.template.exceptions

Thus import should be

from django.template import TemplateDoesNotExist
faxioman commented 7 years ago

Same problem for django 1.9

Andreypnfrv commented 7 years ago

Have same issue with template loaders.

UPD: thanks to @uadnan, his advice worked for me