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
| Attribute | Type | Description |
|---|---|---|
| child_nodelists | tuple = () | 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
| Name | Type | Description |
|---|---|---|
| func | callable | The function to be executed by the node. |
| takes_context | boolean | Flag indicating if the function accepts the template context as its first argument. |
| args | list | A list of positional arguments to pass to the function. |
| kwargs | dict | A dictionary of keyword arguments to pass to the function. |
| target_var | string | The 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
| Name | Type | Description |
|---|---|---|
| func | callable | The template tag function to be executed during rendering |
| takes_context | boolean | A flag indicating whether the function requires the current template context as its first argument |
| args | list | A list of template variables or constants to be passed as positional arguments |
| kwargs | dict | A dictionary of template variables or constants to be passed as keyword arguments |
| target_var | string | The 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
| Name | Type | Description |
|---|---|---|
| context | django.template.Context | The template execution context used to resolve variables and manage output escaping |
Returns
| Type | Description |
|---|---|
string | The function output as a string (escaped if necessary) or an empty string if the output was stored in a context variable |