Like :class:`TemplateNotFound` but raised if multiple templates are selected. This is a subclass of :class:`TemplateNotFound` exception, so just catching the base exception will catch both. .. versionchanged:: 2.11 If a name in the list of names is :class:`Undefined`, a message
| 51 | |
| 52 | |
| 53 | class TemplatesNotFound(TemplateNotFound): |
| 54 | """Like :class:`TemplateNotFound` but raised if multiple templates |
| 55 | are selected. This is a subclass of :class:`TemplateNotFound` |
| 56 | exception, so just catching the base exception will catch both. |
| 57 | |
| 58 | .. versionchanged:: 2.11 |
| 59 | If a name in the list of names is :class:`Undefined`, a message |
| 60 | about it being undefined is shown rather than the empty string. |
| 61 | |
| 62 | .. versionadded:: 2.2 |
| 63 | """ |
| 64 | |
| 65 | def __init__( |
| 66 | self, |
| 67 | names: t.Sequence[t.Union[str, "Undefined"]] = (), |
| 68 | message: t.Optional[str] = None, |
| 69 | ) -> None: |
| 70 | if message is None: |
| 71 | from .runtime import Undefined |
| 72 | |
| 73 | parts = [] |
| 74 | |
| 75 | for name in names: |
| 76 | if isinstance(name, Undefined): |
| 77 | parts.append(name._undefined_message) |
| 78 | else: |
| 79 | parts.append(name) |
| 80 | |
| 81 | parts_str = ", ".join(map(str, parts)) |
| 82 | message = f"none of the templates given were found: {parts_str}" |
| 83 | |
| 84 | super().__init__(names[-1] if names else None, message) |
| 85 | self.templates = list(names) |
| 86 | |
| 87 | |
| 88 | class TemplateSyntaxError(TemplateError): |