Home / File/ templating.py — flask Source File

templating.py — flask Source File

Architecture documentation for templating.py, a python file in the flask codebase. 12 imports, 2 dependents.

File python ApplicationCore Scaffolding 12 imports 2 dependents 8 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  554becd3_25b5_c670_a654_7a20377dec19["templating.py"]
  49f8280b_d7dc_110c_b848_8e7e56bfb19b["ctx.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 49f8280b_d7dc_110c_b848_8e7e56bfb19b
  86817dcd_97b5_9a9f_aee8_5fa78b4cecc9["AppContext"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 86817dcd_97b5_9a9f_aee8_5fa78b4cecc9
  9cff5a62_7dbb_7b80_cf3c_128a7a2fda28["globals.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 9cff5a62_7dbb_7b80_cf3c_128a7a2fda28
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 881f9803_28d6_7d77_c8d7_1098b41ccf84
  8bb2476b_5a2a_1ec8_b02f_463fa3043e16["stream_with_context"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 8bb2476b_5a2a_1ec8_b02f_463fa3043e16
  f7678070_c632_9fab_268f_e2310036493f["signals.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> f7678070_c632_9fab_268f_e2310036493f
  0bdbbb6d_41ac_cb65_54a5_10ce0159c2d6["sansio.app"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 0bdbbb6d_41ac_cb65_54a5_10ce0159c2d6
  c7e51d1e_44dd_175c_9e8a_ba5d5dbfdec4["sansio.scaffold"]
  554becd3_25b5_c670_a654_7a20377dec19 --> c7e51d1e_44dd_175c_9e8a_ba5d5dbfdec4
  7fa0faba_d854_797c_b6bd_20820e905793["debughelpers.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 7fa0faba_d854_797c_b6bd_20820e905793
  20e2a035_64d0_0672_da27_0120172d5eff["explain_template_loading_attempts"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 20e2a035_64d0_0672_da27_0120172d5eff
  d3e9218c_bf0a_48f5_15c9_90795af6f3ac["typing.py"]
  554becd3_25b5_c670_a654_7a20377dec19 --> d3e9218c_bf0a_48f5_15c9_90795af6f3ac
  080c4713_770c_bdc4_fb40_89df334e08bb["jinja2"]
  554becd3_25b5_c670_a654_7a20377dec19 --> 080c4713_770c_bdc4_fb40_89df334e08bb
  e1ae29a1_73d3_d5e9_3fd5_548f4ac50138["__init__.py"]
  e1ae29a1_73d3_d5e9_3fd5_548f4ac50138 --> 554becd3_25b5_c670_a654_7a20377dec19
  9612cfdd_2178_92c0_2ed7_16ebb0c72901["app.py"]
  9612cfdd_2178_92c0_2ed7_16ebb0c72901 --> 554becd3_25b5_c670_a654_7a20377dec19
  style 554becd3_25b5_c670_a654_7a20377dec19 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import typing as t

from jinja2 import BaseLoader
from jinja2 import Environment as BaseEnvironment
from jinja2 import Template
from jinja2 import TemplateNotFound

from .ctx import AppContext
from .globals import app_ctx
from .helpers import stream_with_context
from .signals import before_render_template
from .signals import template_rendered

if t.TYPE_CHECKING:  # pragma: no cover
    from .sansio.app import App
    from .sansio.scaffold import Scaffold


def _default_template_ctx_processor() -> dict[str, t.Any]:
    """Default template context processor.  Injects `request`,
    `session` and `g`.
    """
    ctx = app_ctx._get_current_object()
    rv: dict[str, t.Any] = {"g": ctx.g}

    if ctx.has_request:
        rv["request"] = ctx.request
        rv["session"] = ctx.session

    return rv


class Environment(BaseEnvironment):
    """Works like a regular Jinja environment but has some additional
    knowledge of how Flask's blueprint works so that it can prepend the
    name of the blueprint to referenced templates if necessary.
    """

    def __init__(self, app: App, **options: t.Any) -> None:
        if "loader" not in options:
            options["loader"] = app.create_global_jinja_loader()
        BaseEnvironment.__init__(self, **options)
        self.app = app


class DispatchingJinjaLoader(BaseLoader):
    """A loader that looks for templates in the application and all
    the blueprint folders.
    """

    def __init__(self, app: App) -> None:
        self.app = app

    def get_source(
        self, environment: BaseEnvironment, template: str
    ) -> tuple[str, str | None, t.Callable[[], bool] | None]:
        if self.app.config["EXPLAIN_TEMPLATE_LOADING"]:
            return self._get_source_explained(environment, template)
// ... (152 more lines)

Subdomains

Frequently Asked Questions

What does templating.py do?
templating.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, Scaffolding subdomain.
What functions are defined in templating.py?
templating.py defines 8 function(s): _default_template_ctx_processor, _render, _stream, render_template, render_template_string, sansio, stream_template, stream_template_string.
What does templating.py depend on?
templating.py imports 12 module(s): AppContext, ctx.py, debughelpers.py, explain_template_loading_attempts, globals.py, helpers.py, jinja2, sansio.app, and 4 more.
What files import templating.py?
templating.py is imported by 2 file(s): __init__.py, app.py.
Where is templating.py in the architecture?
templating.py is located at src/flask/templating.py (domain: ApplicationCore, subdomain: Scaffolding, directory: src/flask).

Analyze Your Own Codebase

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

Try Supermodel Free