class documentation

class LoopContext:

Known subclasses: jinja2.runtime.AsyncLoopContext

View In Hierarchy

A wrapper iterable for dynamic for loops, with information about the loop and iteration.
Static Method ​_to​_iterator Undocumented
Method __call__ When iterating over nested data, render the body of the loop recursively with the given inner iterable data.
Method __init__ No summary
Method __iter__ Undocumented
Method __len__ Undocumented
Method __next__ Undocumented
Method __repr__ Undocumented
Method ​_peek​_next No summary
Method changed Return True if previously called with a different value (including when called for the first time).
Method cycle Return a value from the given args, cycling through based on the current index0.
Class Variable ​_length Undocumented
Class Variable index0 Undocumented
Instance Variable ​_after Undocumented
Instance Variable ​_before Undocumented
Instance Variable ​_current Undocumented
Instance Variable ​_iterable Undocumented
Instance Variable ​_iterator Undocumented
Instance Variable ​_last​_changed​_value Undocumented
Instance Variable ​_recurse Undocumented
Instance Variable ​_undefined Undocumented
Instance Variable depth0 Undocumented
Property depth How many levels deep a recursive loop currently is, starting at 1.
Property first Whether this is the first iteration of the loop.
Property index Current iteration of the loop, starting at 1.
Property last Whether this is the last iteration of the loop.
Property length Length of the iterable.
Property nextitem The item in the next iteration. Undefined during the last iteration.
Property previtem The item in the previous iteration. Undefined during the first iteration.
Property revindex Number of iterations from the end of the loop, ending at 1.
Property revindex0 Number of iterations from the end of the loop, ending at 0.
@staticmethod
def _to_iterator(iterable):

Undocumented

Parameters
iterable:t.Iterable[V]Undocumented
Returns
t.Iterator[V]Undocumented
@internalcode
def __call__(self, iterable):

When iterating over nested data, render the body of the loop recursively with the given inner iterable data.

The loop must have the recursive marker for this to work.

Parameters
iterable:t.Iterable[V]Undocumented
Returns
strUndocumented
def __init__(self, iterable, undefined, recurse=None, depth0=0):
Parameters
iterable:t.Iterable[V]Iterable to wrap.
undefined:t.Type[Undefined]Undefined class to use for next and previous items.
recurse:t.Optional[LoopRenderFunc]The function to render the loop body when the loop is marked recursive.
depth0:intIncremented when looping recursively.
def __iter__(self):

Undocumented

Returns
LoopContextUndocumented
def __len__(self):

Undocumented

Returns
intUndocumented
def __next__(self):

Undocumented

Returns
t.Tuple[t.Any, LoopContext]Undocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def _peek_next(self):
Return the next element in the iterable, or missing if the iterable is exhausted. Only peeks one item ahead, caching the result in _last for use in subsequent checks. The cache is reset when __next__ is called.
Returns
t.AnyUndocumented
def changed(self, *value):
Return True if previously called with a different value (including when called for the first time).
Parameters
*value:t.AnyOne or more values to compare to the last call.
Returns
boolUndocumented
def cycle(self, *args):
Return a value from the given args, cycling through based on the current index0.
Parameters
*args:VOne or more values to cycle through.
Returns
VUndocumented
_length: t.Optional[int] =

Undocumented

index0: int =

Undocumented

_after =

Undocumented

_before =

Undocumented

_current =

Undocumented

_iterable =

Undocumented

_iterator =

Undocumented

_last_changed_value =

Undocumented

_recurse =

Undocumented

_undefined =

Undocumented

depth0 =

Undocumented

@property
depth: int =
How many levels deep a recursive loop currently is, starting at 1.
@property
first: bool =
Whether this is the first iteration of the loop.
@property
index: int =
Current iteration of the loop, starting at 1.
@property
last: bool =

Whether this is the last iteration of the loop.

Causes the iterable to advance early. See itertools.groupby for issues this can cause. The groupby filter avoids that issue.

@property
length: int =

Length of the iterable.

If the iterable is a generator or otherwise does not have a size, it is eagerly evaluated to get a size.

@property
nextitem: t.Union[t.Any, Undefined] =

The item in the next iteration. Undefined during the last iteration.

Causes the iterable to advance early. See itertools.groupby for issues this can cause. The jinja-filters.groupby filter avoids that issue.

@property
previtem: t.Union[t.Any, Undefined] =
The item in the previous iteration. Undefined during the first iteration.
@property
revindex: int =

Number of iterations from the end of the loop, ending at 1.

Requires calculating length.

@property
revindex0: int =

Number of iterations from the end of the loop, ending at 0.

Requires calculating length.