summaryrefslogtreecommitdiff
path: root/django/template
diff options
context:
space:
mode:
authorJonathan Stròˆbele <mail@jonathanstroebele.de>2025-02-13 16:23:29 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-02-24 16:25:53 +0100
commit240421c7c4c81fe5df26274b807266bd4ca73d7f (patch)
treee9f57be777f592e51687b8f731f2dc80fac373b2 /django/template
parent582ba18d56167587e290545f113d3956e73a5801 (diff)
Fixed #36186 -- Added forloop.length variable within a template for loop.
Diffstat (limited to 'django/template')
-rw-r--r--django/template/defaulttags.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 1152452081..9023bcc87d 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -206,7 +206,10 @@ class ForNode(Node):
unpack = num_loopvars > 1
# Create a forloop value in the context. We'll update counters on each
# iteration just below.
- loop_dict = context["forloop"] = {"parentloop": parentloop}
+ loop_dict = context["forloop"] = {
+ "parentloop": parentloop,
+ "length": len_values,
+ }
for i, item in enumerate(values):
# Shortcuts for current loop iteration number.
loop_dict["counter0"] = i