Hi,

I'm not really an expert in that part. From what I can read in the documentation, TemplatesSetting isn't a template backend, so why do you think you can specify it in TEMPLATES[x]['BACKEND']? It appears to be a form renderer, which means you can specify it in FORM_RENDERER.

But of course I may have understood something wrong myself.

Regards,

Antonis



On 03/04/2022 20.56, run_the_race wrote:
I was going to report a bug, but the guide recommends asking here first.

While trying to override a built in widget template (still stuck on it here: https://forum.djangoproject.com/t/overriding-widgets-templates-not-working-following-help-template-loader-not-searching-app-dirs/12974), I came across this weird behavoir:

In `django/forms/renderers.py` line 59 it has:
```
class TemplatesSetting(BaseRenderer):
    """
    Load templates using template.loader.get_template() which is configured
    based on settings.TEMPLATES.
    """
    def get_template(self, template_name):
        return get_template(template_name)
```
However a new project with:
```
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',
            ],
        },
    },
    {
        'BACKEND': 'django.forms.renderers.TemplatesSetting',
        'DIRS': ['/my/overide/dir/path',],
        'APP_DIRS': False,
    },
]
```

Generates the error:
```

Traceback (most recent call last):
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", line 66, in __getitem__
    return self._engines[alias]
KeyError: 'renderers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/michael/project/src/manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/commands/check.py", line 63, in handle
    self.check(
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", line 438, in check
    all_issues = checks.run_checks(
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/core/checks/registry.py", line 77, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
    for engine in engines.all():
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", line 90, in all
    return [self[alias] for alias in self]
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", line 90, in <listcomp>
    return [self[alias] for alias in self]
  File "/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", line 81, in __getitem__
    engine = engine_cls(params)
TypeError: TemplatesSetting() takes no arguments
```

How does one configure `django.forms.renderers.TemplatesSetting` without it throwing an error?
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b5182cf-cef1-463b-bb6a-2fb96b893b56n%40googlegroups.com <https://groups.google.com/d/msgid/django-users/2b5182cf-cef1-463b-bb6a-2fb96b893b56n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/77d0dd37-b0bb-ec64-cc05-a59712a3a54d%40antonischristofides.com.

Reply via email to