MCPcopy
hub / github.com/pallets/jinja / from_string

Method from_string

src/jinja2/environment.py:1092–1111  ·  src/jinja2/environment.py::Environment.from_string

Load a template from a source string without using :attr:`loader`. :param source: Jinja source to compile into a template. :param globals: Extend the environment :attr:`globals` with these extra variables available for all renders of this template. If

(
        self,
        source: t.Union[str, nodes.Template],
        globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
        template_class: t.Optional[t.Type["Template"]] = None,
    )

Source from the content-addressed store, hash-verified

1090 return self.select_template(template_name_or_list, parent, globals)
1091
1092 def from_string(
1093 self,
1094 source: t.Union[str, nodes.Template],
1095 globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
1096 template_class: t.Optional[t.Type[class="st">"Template"]] = None,
1097 ) -> class="st">"Template":
1098 class="st">"""Load a template from a source string without using
1099 :attr:`loader`.
1100
1101 :param source: Jinja source to compile into a template.
1102 :param globals: Extend the environment :attr:`globals` with
1103 these extra variables available for all renders of this
1104 template. If the template has already been loaded and
1105 cached, its globals are updated with any new items.
1106 :param template_class: Return an instance of this
1107 :class:`Template` class.
1108 class="st">"""
1109 gs = self.make_globals(globals)
1110 cls = template_class or self.template_class
1111 return cls.from_code(self, self.compile(source), gs, None)
1112
1113 def make_globals(
1114 self, d: t.Optional[t.MutableMapping[str, t.Any]]

Calls 3

make_globalsMethod · 0.95
compileMethod · 0.95
from_codeMethod · 0.80