diff options
| author | Jonathan Stròˆbele <mail@jonathanstroebele.de> | 2025-02-13 16:23:29 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-02-24 16:25:53 +0100 |
| commit | 240421c7c4c81fe5df26274b807266bd4ca73d7f (patch) | |
| tree | e9f57be777f592e51687b8f731f2dc80fac373b2 /django/template | |
| parent | 582ba18d56167587e290545f113d3956e73a5801 (diff) | |
Fixed #36186 -- Added forloop.length variable within a template for loop.
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/defaulttags.py | 5 |
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 |
