RenderContext
A stack container for storing Template state.
Attributes
| Attribute | Type | Description |
|---|---|---|
| template | [Template](../base/template.md?sid=django_template_base_template) = null | The 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
| Name | Type | Description |
|---|---|---|
| key | string | The variable name to retrieve from the current scope. |
| otherwise | any = null | The fallback value to return if the key does not exist in the current scope. |
Returns
| Type | Description |
|---|---|
any | The 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
| Name | Type | Description |
|---|---|---|
| template | [Template](../base/template.md?sid=django_template_base_template) | The template object currently being rendered to track state context. |
| isolated_context | boolean = true | Determines whether to push a fresh, empty dictionary onto the stack to isolate variables for the duration of the block. |
Returns
| Type | Description |
|---|---|
contextmanager | A context manager that restores the previous template and pops the scope upon exit. |