(This has the special feature that the result of Engine.from_string() is
wrapped to construct an instance of the Template class defined in the
backend definition file: django/template/backends/django.py#30 This
Template class differs from the Engine-delivered Template in that it
accepts a dictionary as the context, see
https://docs.djangoproject.com/en/4.1/topics/templates/#django.template.backends.base.Template.render.)
The problem is that it is difficult to retrieve the default template
backend in order to call .from_string() on it. However, a function already
exists to retrieve the default template backend's *engine*.
The default backend's engine is retrieved via
django.template.Engine.get_default(). This function identifies the first
configured DjangoTemplates backend, and then returns its .engine
attribute. As a result, when from_string() is called, it will be called on
the engine and not on the backend, thus the wrapping Template() call is
missing.
I am proposing to add a get_default_backend() function to
django.template.Engine, which is like get_default(), but returns the
backend itself (and not its .engine attribute). This would allow calling
.from_string() directly on the backend subsequently. -- get_default() can
then be adjusted to simply return get_default_backend().engine.
While trying to solve the issue (context argument type mismatch: dict vs
Context), I found the docs not very helpful, as they are not very accurate
in the distinction between a backend and its engine. I've also added a
commit that clarifies that language.
I have submitted a patch here: https://github.com/django/django/pull/15944
For discussion on the list, see here: https://groups.google.com/g/django-
developers/c/BfB9QsDMMAI
--
Ticket URL: <https://code.djangoproject.com/ticket/33943>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: assigned => closed
* resolution: => needsinfo
Comment:
I'll close as needsinfo pending the mailing list discussion. (We can
reopen if we decide to progress.) Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/33943#comment:1>