Home / Function/ explain_template_loading_attempts() — flask Function Reference

explain_template_loading_attempts() — flask Function Reference

Architecture documentation for the explain_template_loading_attempts() function in debughelpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  20e2a035_64d0_0672_da27_0120172d5eff["explain_template_loading_attempts()"]
  7fa0faba_d854_797c_b6bd_20820e905793["debughelpers.py"]
  20e2a035_64d0_0672_da27_0120172d5eff -->|defined in| 7fa0faba_d854_797c_b6bd_20820e905793
  a0ae334c_2e07_622b_8d12_f4de60d403d1["_get_source_explained()"]
  a0ae334c_2e07_622b_8d12_f4de60d403d1 -->|calls| 20e2a035_64d0_0672_da27_0120172d5eff
  42fbaf94_6e69_e270_9d95_547ffb5ea796["_dump_loader_info()"]
  20e2a035_64d0_0672_da27_0120172d5eff -->|calls| 42fbaf94_6e69_e270_9d95_547ffb5ea796
  style 20e2a035_64d0_0672_da27_0120172d5eff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/debughelpers.py lines 124–179

def explain_template_loading_attempts(
    app: App,
    template: str,
    attempts: list[
        tuple[
            BaseLoader,
            Scaffold,
            tuple[str, str | None, t.Callable[[], bool] | None] | None,
        ]
    ],
) -> None:
    """This should help developers understand what failed"""
    info = [f"Locating template {template!r}:"]
    total_found = 0
    blueprint = None

    if (ctx := _cv_app.get(None)) is not None and ctx.has_request:
        blueprint = ctx.request.blueprint

    for idx, (loader, srcobj, triple) in enumerate(attempts):
        if isinstance(srcobj, App):
            src_info = f"application {srcobj.import_name!r}"
        elif isinstance(srcobj, Blueprint):
            src_info = f"blueprint {srcobj.name!r} ({srcobj.import_name})"
        else:
            src_info = repr(srcobj)

        info.append(f"{idx + 1:5}: trying loader of {src_info}")

        for line in _dump_loader_info(loader):
            info.append(f"       {line}")

        if triple is None:
            detail = "no match"
        else:
            detail = f"found ({triple[1] or '<string>'!r})"
            total_found += 1
        info.append(f"       -> {detail}")

    seems_fishy = False
    if total_found == 0:
        info.append("Error: the template could not be found.")
        seems_fishy = True
    elif total_found > 1:
        info.append("Warning: multiple loaders returned a match for the template.")
        seems_fishy = True

    if blueprint is not None and seems_fishy:
        info.append(
            "  The template was looked up from an endpoint that belongs"
            f" to the blueprint {blueprint!r}."
        )
        info.append("  Maybe you did not place a template in the right folder?")
        info.append("  See https://flask.palletsprojects.com/blueprints/#templates")

    app.logger.info("\n".join(info))

Subdomains

Frequently Asked Questions

What does explain_template_loading_attempts() do?
explain_template_loading_attempts() is a function in the flask codebase, defined in src/flask/debughelpers.py.
Where is explain_template_loading_attempts() defined?
explain_template_loading_attempts() is defined in src/flask/debughelpers.py at line 124.
What does explain_template_loading_attempts() call?
explain_template_loading_attempts() calls 1 function(s): _dump_loader_info.
What calls explain_template_loading_attempts()?
explain_template_loading_attempts() is called by 1 function(s): _get_source_explained.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free