#27130: Allow using the DjangoTemplates engine without configuring settings
-------------------------------------+-------------------------------------
Reporter: Al Johri | Owner: reficul31
Type: | Status: closed
Cleanup/optimization |
Component: Template system | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Aymeric Augustin):
* status: assigned => closed
* resolution: => wontfix
Comment:
Perhaps this analogy will help:
django.template.Engine ~ sqlite3.connect
django.template.backends.django.DjangoTemplates ~
django.db.backends.sqlite3.base.DatabaseWrapper
The two live in the same namespace for historical reasons. Moving the
implementation of the engine outside of `django.template` would be
backwards incompatible for no significant benefit.
I wrote a
[https://github.com/django/django/blob/master/django/template/__init__.py
large docstring] to clarify which modules belong to the standalone
template engine and which modules allow using arbitrary backends with a
unified API. See also DEP 182.
----
Replying to [comment:14 reficul31]:
> I read over the docs of the django.template.engine and knew that it
worked in standalone mode.
If you think the docs could state more clearly that this is the API to use
if you want to use the Django template engine in standalone mode, let's
improve them.
(Since it's hard to figure out how docs that you wrote yourself could be
unclear to others, I'm not in the best position to do that.)
> I thought the gist of the ticket was to provide DjangoTemplates with
that functionality too.
Unfortunately, it was incorrectly accepted based on a misunderstanding. It
should have been closed as wontfix. I realized the problem only when I saw
your PR.
> I might be wrong but is it a functionality that could cause problems?
Yes, it would worsen the problem that the existence of this ticket
demonstrates.
Even though the documentation is unambiguous, there's already some
confusion between the concepts of "template engine" (any library that can
render templates) and "template backend" (a thin integration layer for
configuring a template engine from Django settings). Adding to the
ambiguity by blurring the roles of Engine and DjangoTemplates would
increase confusion.
> Eg. For most of my projects I use DjangoTemplates backend and it would
be nice if i could test my templates on it.
DjangoTemplates is nothing more than an Engine configured from Django
settings. Here's the whole implementation:
{{{
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
options.setdefault('autoescape', True)
options.setdefault('debug', settings.DEBUG)
options.setdefault('file_charset', settings.FILE_CHARSET)
libraries = options.get('libraries', {})
options['libraries'] = self.get_templatetag_libraries(libraries)
super().__init__(params)
self.engine = Engine(self.dirs, self.app_dirs, **options)
}}}
and then there's a couple methods that forward to the corresponding
methods on Engine.
If your projet uses Django settings and the DjangoTemplates backend, then
your tests should use Django settings as well, and there's no use making
DjangoTemplates work without settings.
If your projet doesn't use Django settings and configures an Engine in
standalone mode, then you don't use DjangoTemplates, not does it make any
sense, since you don't have Django settings.
--
Ticket URL: <https://code.djangoproject.com/ticket/27130#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.4f6b233219f7168128874750247ee927%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.