0

I'd like to know if there's a way to reference the individual forms of a formset in Django without using a for loop.

This is what all the docs search results point to:

    {% for form in formset %}
        {{ form }}
    {% endfor %}

I'd like to know if there's anyway to do this:

    {{ form[0] }}
    {{ form[1] }}
    {{ form[2] }}

I can't find anything that does it and beginning to think it's not possible.

goose
  • 2,502
  • 6
  • 42
  • 69
  • The question is unclear, in the first block you are rendering the full form, in the second block you are trying to render a form field. If `formset` supports indexing, then `formset.0` shall give you the first form. And then you can try to access a particular field using `formset.0.field` – awesoon Jun 11 '19 at 05:39
  • Thanks @awesoon. Despite my error, you've managed to answer my question. I'll edit inline with what I had intended. – goose Jun 11 '19 at 11:51
  • Possible duplicate of [Reference list item by index within Django template?](https://stackoverflow.com/questions/4651172/reference-list-item-by-index-within-django-template) – awesoon Jun 11 '19 at 11:52
  • If the issue is only with `form[0]` vs `form.0`, then the linked question contains some related info. – awesoon Jun 11 '19 at 11:53

0 Answers0