Is there a list of objects when sending requests in html?

0

I'm developing a small python (flask) web project for self-learning and came across something I've never faced before.

I have a registration form where the fields of an information are dynamic, ie via jquery I can create and delete fields because I do not know how many links the user will send. My question is as follows, how do I get the request of this form in my python code if I do not know how many fields will be sent? Is there any sort of list in the request where I can create 'objects' to send everything together?

    
asked by anonymous 16.08.2018 / 22:00

1 answer

1

As documentation says here , request.form is ImmutableMultiDict which behaves like a dictionary.

You can use dictionary methods in it normally, such as request.form.keys() , request.form.items() , or even iterate directly into it to see all names used:

for chave in request.form:
    print(chave, request.form[chave])

It will print everything on the console that came from the form.

If your page sends multiple fields with the same name, you can still pick up using getlist :

request.form.getlist(chave)

It will return a list with all values with that name.

    
16.08.2018 / 22:24