nodejs/node · error · TemplatesNotFound

none of the templates given were found: %s

Error message

none of the templates given were found: %s

What it means

Raised by Environment.select_template (jinja2 environment.py) after the loop over candidate names completes without any TemplateFound. Each candidate was tried via _load_template and each raised TemplateNotFound; the resulting TemplatesNotFound carries the list of names so the caller can see what was searched. The message format string 'none of the templates given were found: %s' is the canonical rendering of that exception.

Source

Thrown at tools/inspector_protocol/jinja2/environment.py:857

        .. versionchanged:: 2.4
           If `names` contains a :class:`Template` object it is returned
           from the function unchanged.
        """
        if not names:
            raise TemplatesNotFound(message=u'Tried to select from an empty list '
                                            u'of templates.')
        globals = self.make_globals(globals)
        for name in names:
            if isinstance(name, Template):
                return name
            if parent is not None:
                name = self.join_path(name, parent)
            try:
                return self._load_template(name, globals)
            except TemplateNotFound:
                pass
        raise TemplatesNotFound(names)

    @internalcode
    def get_or_select_template(self, template_name_or_list,
                               parent=None, globals=None):
        """Does a typecheck and dispatches to :meth:`select_template`
        if an iterable of template names is given, otherwise to
        :meth:`get_template`.

        .. versionadded:: 2.3
        """
        if isinstance(template_name_or_list, string_types):
            return self.get_template(template_name_or_list, parent, globals)
        elif isinstance(template_name_or_list, Template):
            return template_name_or_list
        return self.select_template(template_name_or_list, parent, globals)

    def from_string(self, source, globals=None, template_class=None):
        """Load a template from a string.  This parses the source given and

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify each candidate exists with env.loader.list_templates() or by listing the loader's source paths.
  2. Add a guaranteed default template as the final fallback in the list.
  3. Check loader base path, package name, and filename casing against the candidates.

Example fix

# before
env.select_template(['header_a.html','header_b.html'])
# after
env.select_template(['header_a.html','header_b.html','header_default.html'])
Defensive patterns

Strategy: try-catch

Validate before calling

available = set(env.loader.list_templates())
missing = [n for n in candidates if n not in available]
if missing:
    raise FileNotFoundError('templates not in loader: %s' % missing)

Try / catch

from jinja2 import TemplatesNotFound
try:
    tpl = env.select_template(candidates)
except TemplatesNotFound as e:
    tpl = env.get_template('default.html')   # last-resort fallback

Prevention

When it happens

Trigger: Calling select_template(['a.html','b.html','c.html']) when none of a/b/c exist in the loader's search paths; loader misconfigured (wrong directory, wrong package, missing template bundle); template-name typos across the board.

Common situations: Theme/skin fallback chains where none of the named themes are installed; deploying without the templates directory; loader rooted at the wrong path; case-sensitivity mismatch on case-sensitive filesystems.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/ba4661c872a7ec4b. Report an issue: GitHub.