Home / Function/ get_template_attribute() — flask Function Reference

get_template_attribute() — flask Function Reference

Architecture documentation for the get_template_attribute() function in helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  17318abb_04de_ea35_68be_29d1e2a3c8e3["get_template_attribute()"]
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  17318abb_04de_ea35_68be_29d1e2a3c8e3 -->|defined in| 881f9803_28d6_7d77_c8d7_1098b41ccf84
  style 17318abb_04de_ea35_68be_29d1e2a3c8e3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/helpers.py lines 291–310

def get_template_attribute(template_name: str, attribute: str) -> t.Any:
    """Loads a macro (or variable) a template exports.  This can be used to
    invoke a macro from within Python code.  If you for example have a
    template named :file:`_cider.html` with the following contents:

    .. sourcecode:: html+jinja

       {% macro hello(name) %}Hello {{ name }}!{% endmacro %}

    You can access this from Python code like this::

        hello = get_template_attribute('_cider.html', 'hello')
        return hello('World')

    .. versionadded:: 0.2

    :param template_name: the name of the template
    :param attribute: the name of the variable of macro to access
    """
    return getattr(current_app.jinja_env.get_template(template_name).module, attribute)

Subdomains

Frequently Asked Questions

What does get_template_attribute() do?
get_template_attribute() is a function in the flask codebase, defined in src/flask/helpers.py.
Where is get_template_attribute() defined?
get_template_attribute() is defined in src/flask/helpers.py at line 291.

Analyze Your Own Codebase

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

Try Supermodel Free