MCPcopy
hub / github.com/django/django / get_template

Method get_template

django/template/loaders/base.py:8–35  ·  view source on GitHub ↗

Call self.get_template_sources() and return a Template object for the first template matching template_name. If skip is provided, ignore template origins in skip. This is used to avoid recursion during template extending.

(self, template_name, skip=None)

Source from the content-addressed store, hash-verified

6 self.engine = engine
7
8 def get_template(self, template_name, skip=None):
9 """
10 Call self.get_template_sources() and return a Template object for
11 the first template matching template_name. If skip is provided, ignore
12 template origins in skip. This is used to avoid recursion during
13 template extending.
14 """
15 tried = []
16
17 for origin in self.get_template_sources(template_name):
18 if skip is not None and origin in skip:
19 tried.append((origin, "Skipped to avoid recursion"))
20 continue
21
22 try:
23 contents = self.get_contents(origin)
24 except TemplateDoesNotExist:
25 tried.append((origin, "Source does not exist"))
26 continue
27 else:
28 return Template(
29 contents,
30 origin,
31 origin.template_name,
32 self.engine,
33 )
34
35 raise TemplateDoesNotExist(template_name, tried=tried)
36
37 def get_template_sources(self, template_name):
38 """

Callers

nothing calls this directly

Calls 5

get_template_sourcesMethod · 0.95
get_contentsMethod · 0.95
TemplateClass · 0.90
appendMethod · 0.45

Tested by

no test coverage detected