I'm new to flask and WTForms so sorry in advance.
Anyways, I'm trying to create multiple forms using the same form defined below in forms.py
File_Choices = [('1', 'ex1.pdf'), ('2', 'ex2.pdf')
class Inputs(Form):
Files = SelectField(u'File', choices=File_Choices,validators =[Required()])
I am familiar with the fact that I have to declare something along the lines of: form1=Inputs() to declare a form in the views.py, however the problem arises when I need to declare an unknown amount of forms and track the selected values.
My specific problem is that I have a list that contains N elements and each element has to correspond to a file that the user selects from the form. So I've broken down my problem to just creating N number of forms first and thought about using a for loop like this:
for i in range(len(PDF_list))
form'i'=Input()
So the end product if the length of the list is 5, is 5 Input forms declared as form1, form2, form3, form4, form5. I know this obviously doesn’t work the way I just coded it but that's the functionality I'm trying to get so I can still access the submitted values using something like
dict(File_Choices).get(form'i'.Files.data).
Theres probably a really obvious way to do this however, I'm new to using flask and WTForms so any help is appreciated and in your solution if you could explain step by step what you're doing since I'm new, that would be awesome.