A
A
aial2017-06-27 17:57:53
Flask
aial, 2017-06-27 17:57:53

When receiving data via getlist, I can't get variables in a loop?

When receiving data via getlist, I cannot get variables in a loop.

<input type="hidden" id="list_id" name="list_id" value="1,2,3,4,5,6,7,8,9,10">

view.py
list_id = request.form.getlist('list_id')
        for i in list_id:
            print(type(i))
            print(i)

and output this:
<class 'str'>
1,2,3,4,5,6,7,8,9,10

And I need to count each number separately.
like:
<class 'str'>
1
<class 'str'>
2
<class 'str'>
3
<class 'str'>
4

for it to be

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2017-06-27
@aial

list_ids = request.form.get('list_id', "").split(",")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question