Path 1: 1 calls (1.0)

Flask (1)

'missing_template.html' (1)

list (1)

1def explain_template_loading_attempts(app: Flask, template, attempts) -> None:
2    """This should help developers understand what failed"""
3    info = [f"Locating template {template!r}:"]
4    total_found = 0
5    blueprint = None
6    if request_ctx and request_ctx.request.blueprint is not None:
7        blueprint = request_ctx.request.blueprint
8
9    for idx, (loader, srcobj, triple) in enumerate(attempts):
10        if isinstance(srcobj, Flask):
11            src_info = f"application {srcobj.import_name!r}"
12        elif isinstance(srcobj, Blueprint):
13            src_info = f"blueprint {srcobj.name!r} ({srcobj.import_name})"
14        else:
15            src_info = repr(srcobj)
16
17        info.append(f"{idx + 1:5}: trying loader of {src_info}")
18
19        for line in _dump_loader_info(loader):
20            info.append(f"       {line}")
21
22        if triple is None:
23            detail = "no match"
24        else:
25            detail = f"found ({triple[1] or '<string>'!r})"
26            total_found += 1
27        info.append(f"       -> {detail}")
28
29    seems_fishy = False
30    if total_found == 0:
31        info.append("Error: the template could not be found.")
32        seems_fishy = True
33    elif total_found > 1:
34        info.append("Warning: multiple loaders returned a match for the template.")
35        seems_fishy = True
36
37    if blueprint is not None and seems_fishy:
38        info.append(
39            "  The template was looked up from an endpoint that belongs"
40            f" to the blueprint {blueprint!r}."
41        )
42        info.append("  Maybe you did not place a template in the right folder?")
43        info.append("  See https://flask.palletsprojects.com/blueprints/#templates")
44
45    app.logger.info("\n".join(info))