Skip to main content

RenderContext

A stack container for storing Template state.

Attributes

AttributeTypeDescription
template[Template](../base/template.md?sid=django_template_base_template) = nullThe template object currently being rendered within the context stack.

Constructor

Signature

def RenderContext() - > null

Methods


get()

@classmethod
def get(
key: string,
otherwise: any = null
) - > any

Retrieves a value from the current scope by key, returning a default value if the key is not found.

Parameters

NameTypeDescription
keystringThe variable name to retrieve from the current scope.
otherwiseany = nullThe fallback value to return if the key does not exist in the current scope.

Returns

TypeDescription
anyThe value associated with the key in the current scope, or the provided default value.

push_state()

@classmethod
def push_state(
template: [Template](../base/template.md?sid=django_template_base_template),
isolated_context: boolean = true
) - > contextmanager

Manages template state by updating the current template reference and optionally pushing a new isolated scope onto the stack.

Parameters

NameTypeDescription
template[Template](../base/template.md?sid=django_template_base_template)The template object currently being rendered to track state context.
isolated_contextboolean = trueDetermines whether to push a fresh, empty dictionary onto the stack to isolate variables for the duration of the block.

Returns

TypeDescription
contextmanagerA context manager that restores the previous template and pops the scope upon exit.