I'm not quite sure how approach this matter. I hope i get there.
For example I have a table full of addresses on a page. The count of these are dynamic (could be 5 or 10 or any other count). And I want the possibility to edit them on one page.
My approach was to create a Form with wtforms to edit one address and to multiply
it in a jinja2 for loop
and append to the html propertys name
and id
the
loop.index0
from the itereation, so i can extract each row of data manually
and put it back in my form, when I want to evaluate it.
So the Form for this example would be:
class AdressForm(Form):
name = TextField()
so now my template aproach looks like the following (break down to one input field):
{% for address in addresses %}
{{ forms.render_field(addressform.name, id = "name_" ~ loop.index0,
name = "name_" ~ loop.index0, value = address.name) }}
{% endfor %}
(forms.render_field is just a macro to specify the right classes to the field function of wtforms. like they use in many tutorials)
So this is not working, since you can't pass the name
parameter manually to the field function, since wtforms create the name
html-paramter from the variblename of the intial Form.
So is there a way to add a prefix or postfix to the name of a form I want to render.
Or is this a XY-Problem and my approach is totaly wrong.
or have I do it all plain by myself (I really try to avoid this)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…