how to call dynamic form name in the django template

Viewed 14

i have two forms called

`{{form.f1}}` 

and

`{{form.f2}}`.

i would like to acces the two forms(f1 and f2) in the django template via forloop. my forloop is

{% for n in formList %}
{{form.f?}}
{% endfor %}

in my view.py, formList is

{'formList':range(1,3)}

i do not know how to integrate N in the forloop and i need your help to call the dynamic forms.

thanx.

1 Answers

You should probably make your formList a list of those forms, not their indices. Then you could simply iterate over the list and not try to access them using indices.

So:

{'formList': [form.f1, form.f2]}

And then in the template:

{% for f in formList %}
    {{ f }}
{% endfor %}
Related