]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Clarify that last filter doesn't work with generators 926/head
authorPinkFloyded <k.veneetreddy@gmail.com>
Fri, 16 Nov 2018 23:33:46 +0000 (05:03 +0530)
committerPinkFloyded <k.veneetreddy@gmail.com>
Fri, 16 Nov 2018 23:33:46 +0000 (05:03 +0530)
jinja2/filters.py

index 6d3e463f55178e8a7a3fd7475a18e1413afa6f11..bf5173c1a32db9fe82802f4a884b75f73c12dff4 100644 (file)
@@ -440,7 +440,15 @@ def do_first(environment, seq):
 
 @environmentfilter
 def do_last(environment, seq):
-    """Return the last item of a sequence."""
+    """
+    Return the last item of a sequence.
+
+    Note: Does not work with generators. You may want to explicitly convert it to a list:
+
+    .. sourcecode:: jinja
+
+        {{ data | selectattr('name', '==', 'Jinja') | list | last }}
+    """
     try:
         return next(iter(reversed(seq)))
     except StopIteration: