class Context: (source)
The template context holds the variables of a template. It stores the values passed to the template and also the names the template exports. Creating instances is neither supported nor useful as it's created automatically at various stages of the template evaluation and should not be created by hand. The context is immutable. Modifications on :attr:`parent` **must not** happen and modifications on :attr:`vars` are allowed from generated template code only. Template filters and global functions marked as :func:`pass_context` get the active context passed as first argument and are allowed to access the context read-only. The template context supports read only dict operations (`get`, `keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`, `__getitem__`, `__contains__`). Additionally there is a :meth:`resolve` method that doesn't fail with a `KeyError` but returns an :class:`Undefined` object for missing variables.
Method | __contains__ |
Undocumented |
Method | __getitem__ |
Look up a variable by name with ``[]`` syntax, or raise a ``KeyError`` if the key is not found. |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | call |
Call the callable with the arguments and keyword arguments provided but inject the active context or environment as first argument if the callable has :func:`pass_context` or :func:`pass_environment`. |
Method | derived |
Internal helper function to create a derived context. This is used in situations where the system needs a new context in the same template that is independent. |
Method | get |
Look up a variable by name, or return a default if the key is not found. |
Method | get |
Return the complete context as dict including the exported variables. For optimizations reasons this might not return an actual copy so be careful with using it. |
Method | get |
Get a new dict with the exported variables. |
Method | resolve |
Look up a variable by name, or return an :class:`Undefined` object if the key is not found. |
Method | resolve |
Look up a variable by name, or return a ``missing`` sentinel if the key is not found. |
Method | super |
Render a parent block. |
Class Variable | items |
Undocumented |
Class Variable | keys |
Undocumented |
Class Variable | values |
Undocumented |
Instance Variable | blocks |
Undocumented |
Instance Variable | environment |
Undocumented |
Instance Variable | eval |
Undocumented |
Instance Variable | exported |
Undocumented |
Instance Variable | globals |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | parent |
Undocumented |
Instance Variable | vars |
Undocumented |
Undocumented
Parameters | |
environment:Environment | Undocumented |
parent:t.Dict[ | Undocumented |
name:t.Optional[ | Undocumented |
blocks:t.Dict[ | Undocumented |
globals:t.Optional[ | Undocumented |
Call the callable with the arguments and keyword arguments provided but inject the active context or environment as first argument if the callable has :func:`pass_context` or :func:`pass_environment`.
Parameters | |
__self | Undocumented |
__obj:t.Callable | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Union[ | Undocumented |
Internal helper function to create a derived context. This is used in situations where the system needs a new context in the same template that is independent.
Parameters | |
locals:t.Optional[ | Undocumented |
Returns | |
Context | Undocumented |
Look up a variable by name, or return an :class:`Undefined` object if the key is not found. If you need to add custom behavior, override :meth:`resolve_or_missing`, not this method. The various lookup functions use that method, not this one. :param key: The variable name to look up.
Parameters | |
key:str | Undocumented |
Returns | |
t.Union[ | Undocumented |
Look up a variable by name, or return a ``missing`` sentinel if the key is not found. Override this method to add custom lookup behavior. :meth:`resolve`, :meth:`get`, and :meth:`__getitem__` use this method. Don't call this method directly. :param key: The variable name to look up.
Parameters | |
key:str | Undocumented |
Returns | |
t.Any | Undocumented |
Render a parent block.
Parameters | |
name:str | Undocumented |
current:t.Callable[ | Undocumented |
Returns | |
t.Union[ | Undocumented |