Skip to main content

InclusionNode

This class represents a template node that renders a specific template with a context provided by a helper function. It handles the resolution of arguments, manages template loading and caching within the render context, and ensures that essential data like CSRF tokens are propagated to the sub-template.

Attributes

AttributeTypeDescription
filenamestring, [Template](../base/template.md?sid=django_template_base_template), or IterableThe template name, template object, or list of template names used to render the inclusion tag's output.

Constructor

Signature

def InclusionNode(
func: callable,
takes_context: boolean,
args: list,
kwargs: dict,
filename: str|Template|Iterable
) - > null

Parameters

NameTypeDescription
funccallableThe function to be called by the inclusion tag.
takes_contextbooleanFlag indicating if the function accepts the template context as its first argument.
argslistA list of positional arguments for the function.
kwargsdictA dictionary of keyword arguments for the function.
filename`strTemplate

Methods


render()

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

Render the specified template and context. Cache the template object in render_context to avoid reparsing and loading when used in a for loop.

Parameters

NameTypeDescription
contextdjango.template.ContextThe current template rendering context used to resolve arguments and manage the render cache

Returns

TypeDescription
stringThe rendered HTML content of the inclusion template as a string