0

I'm trying to obtain the equivalent in Django's template language. Is this possible? I want to print the final number , not the count each iteration.

int num=0;
for (int i = 0; i < numitems; i++)
{
   num += 1;
}

I've tried:

{% for task in tasks %}
   {{ forloop.counter0 }}
   {counter}
{% endfor %}
4
  • {{ tasks | length }} is what I was looking for, thanks! Commented May 18, 2015 at 8:18
  • ryan, please use answer box to post the answer. As a nice bonus, you can accept your own answer :) Commented May 18, 2015 at 8:21
  • I did that in the hopes that the previous person who deleted their comment would re-comment their answer so I could accept it. Commented May 18, 2015 at 8:22
  • Sorry, I deleted it because i thought I might have been making too many assumptions on what you were looking for. Glad you saw it in time. Commented May 19, 2015 at 12:23

1 Answer 1

2

I think you are looking for:

{{ tasks | length }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.