# How to get the amount of formset stored in a template

**URL:** <https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381>\
**Category:** Using Django\
**Created:** [August 25, 2021, 1:03am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381 "2021-08-25T01:03:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CalvinTheCat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvinthecat/32/5343_2.png) [@CalvinTheCat](https://forum.djangoproject.com/u/CalvinTheCat)\
**Post date:** [August 25, 2021, 1:03am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/1 "2021-08-25T01:03:25Z")

</div>

I have a database which uses formset to help store data. How do i get the ‘value’ of the numbers of data in the template. Like example i got a queryset of {[Item 1],[Item 2]}. How do i get the value of 2 in the template to tell me theres 2 items?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 25, 2021, 1:52am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/2 "2021-08-25T01:52:02Z")

</div>

See [total\_form\_count and initial\_form\_count](https://docs.djangoproject.com/en/3.2/topics/forms/formsets/#total-form-count-and-initial-form-count).

---

<div class="post-metadata">

**Author:** ![CalvinTheCat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvinthecat/32/5343_2.png) [@CalvinTheCat](https://forum.djangoproject.com/u/CalvinTheCat)\
**Post date:** [August 25, 2021, 2:06am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/3 "2021-08-25T02:06:32Z")

</div>

Thanks for the quick response. It’s not working for me. I got the undefined in the console. Is this correct?

```
let data = ('#rowAddition').total_form_count

console.log(data)

```

I tried adding print(deviceInterface.total\_form\_count) in my views, it says queryset dont have such stuff

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 25, 2021, 2:28am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/4 "2021-08-25T02:28:10Z")

</div>

That’s a method on the formset, not a JavaScript function on an element or a function on a model.

---

<div class="post-metadata">

**Author:** ![CalvinTheCat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvinthecat/32/5343_2.png) [@CalvinTheCat](https://forum.djangoproject.com/u/CalvinTheCat)\
**Post date:** [August 25, 2021, 2:30am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/5 "2021-08-25T02:30:31Z")

</div>

Mind giving me a example? Im pretty new to this formset and I cant find guide on youtube

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 25, 2021, 11:23am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/6 "2021-08-25T11:23:24Z")

</div>

So in re-reading your question and how you attempted to use the answer, I realized there are two different possible cases here, each with a different answer.

If you’re trying to obtain the number of forms in the template, while the template is being rendered on the server before it is sent to the browser, you should be able to put `{{ my_formset.total_form_count }}` in your template. (That’s the same technique used to retrieve any attribute of an object in the template - this is not specific to formsets.)

Always keep in mind that the Django objects, attributes, and methods only exist on the server. They are not available in the browser. Once a template has finished being rendered and is returned to the browser, Django is _done_.

If you’re trying to obtain the number of forms in JavaScript in your browser, then you should be able to rely upon the `forms-TOTAL_FORMS` element in the management form. (If you can’t, then you’ve got an issue with how you’re managing the management form.)

---

<div class="post-metadata">

**Author:** ![CalvinTheCat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvinthecat/32/5343_2.png) [@CalvinTheCat](https://forum.djangoproject.com/u/CalvinTheCat)\
**Post date:** [August 26, 2021, 5:09am UTC](https://forum.djangoproject.com/t/how-to-get-the-amount-of-formset-stored-in-a-template/9381/7 "2021-08-26T05:09:28Z")

</div>

Ok, thank you very much for the detail explanation
