Skip to main content

SimpleNode

This class represents a template node that executes a registered function with resolved arguments and keyword arguments. It supports rendering the function's output directly to the template or storing the result in a specified context variable. The class also handles automatic HTML escaping of the output based on the current template context settings.

Attributes

AttributeTypeDescription
child_nodeliststuple = ()A tuple of attribute names representing child node lists that should be traversed during template rendering or inspection.

Constructor

Signature

def SimpleNode(
func: callable,
takes_context: boolean,
args: list,
kwargs: dict,
target_var: string
) - > null

Parameters

NameTypeDescription
funccallableThe function to be executed by the node.
takes_contextbooleanFlag indicating if the function accepts the template context as its first argument.
argslistA list of positional arguments to pass to the function.
kwargsdictA dictionary of keyword arguments to pass to the function.
target_varstringThe name of the context variable where the function output should be stored.

Signature

def SimpleNode(
func: callable,
takes_context: boolean,
args: list,
kwargs: dict,
target_var: string
) - > null

Parameters

NameTypeDescription
funccallableThe template tag function to be executed during rendering
takes_contextbooleanA flag indicating whether the function requires the current template context as its first argument
argslistA list of template variables or constants to be passed as positional arguments
kwargsdictA dictionary of template variables or constants to be passed as keyword arguments
target_varstringThe name of the context variable where the function output should be stored, or None to render directly

Methods


render()

@classmethod
def render(
context: django.template.Context
) - > string

Executes the underlying function with resolved arguments and either stores the result in the context or returns it as a string.

Parameters

NameTypeDescription
contextdjango.template.ContextThe template execution context used to resolve variables and manage output escaping

Returns

TypeDescription
stringThe function output as a string (escaped if necessary) or an empty string if the output was stored in a context variable