Y
Y
Yura2021-03-29 23:10:44
Django
Yura, 2021-03-29 23:10:44

How to display the dynamic number of form fields?

Hello I have a form class like this

class TestForm(forms.Form):
    def __init__(self, amount):
        self.questions_list = []
        super(TestForm, self).__init__()
        for i in range(amount):
            answer = forms.BooleanField(label="Ответ", required=False)
            self.questions_list.append(answer)

In views, I create it and pass it to the template form = TestForm(amount_questions)
The problem is that I can’t display it in the template, {{form.questions_list.0}}
in such and similar ways, please tell me how to solve this problem, well and how will accept the data from the form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maksam07, 2021-04-11
@maksam07

In the tutorial of. site creation documentation, the survey site is being created:
https://docs.djangoproject.com/en/3.2/intro/tutorial01/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question