unsubscribe
- From:
- Matt Freeman
- Date:
- 2011-06-22 @ 07:23
unsubscribe
---- On Tue, 21 Jun 2011 13:19:02 -0700 Santiago Basulto
<santiago.basulto@gmail.com> wrote ----
Hello people.
I've a little problem here.
I've a variable number of input items to show in a form. I mean, the
user clicks an "add button" and another input is added to the DOM.
The problem is that i don't know how to get that data from the view.
For example, in Django, If i give all the inputs the same name (say,
invoice-row), i can issue the getlist method, this way:
request.POST.getlist('invoice-row')
But here, if i do:
request.form["invoice-row"] i get the first one.
I think i could give diferent names with Javascript ( invoice-row-1,
invoice-row-2, etc) and then get them.
But, is there a better way of doing this?
Thanks a lot!
--
Santiago Basulto.-
Re: [flask] Get data from Multiple form Inputs (with the same name)
- From:
- Steven Kryskalla
- Date:
- 2011-06-21 @ 20:32
On Tue, Jun 21, 2011 at 4:19 PM, Santiago Basulto
<santiago.basulto@gmail.com> wrote:
> For example, in Django, If i give all the inputs the same name (say,
> invoice-row), i can issue the getlist method, this way:
>
> request.POST.getlist('invoice-row')
>
> But here, if i do:
>
> request.form["invoice-row"] i get the first one.
>
request.form.getlist('invoice-row') will do the same as django's
request.POST.getlist('invoice-row')
See here for more info:
http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.MultiDict.getlist
-Steve
Re: [flask] Get data from Multiple form Inputs (with the same name)
- From:
- Santiago Basulto
- Date:
- 2011-06-21 @ 20:38
Thanks Steve!
It works really well.
I didn't see it here: http://flask.pocoo.org/docs/api/#incoming-request-data
Then i thought it didn't exist.
Should i check the API that you sent in the future?
2011/6/21 Steven Kryskalla <skryskalla@gmail.com>:
> On Tue, Jun 21, 2011 at 4:19 PM, Santiago Basulto
> <santiago.basulto@gmail.com> wrote:
>> For example, in Django, If i give all the inputs the same name (say,
>> invoice-row), i can issue the getlist method, this way:
>>
>> request.POST.getlist('invoice-row')
>>
>> But here, if i do:
>>
>> request.form["invoice-row"] i get the first one.
>>
>
> request.form.getlist('invoice-row') will do the same as django's
> request.POST.getlist('invoice-row')
>
> See here for more info:
>
>
http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.MultiDict.getlist
>
> -Steve
>
--
Santiago Basulto.-
Re: [flask] Get data from Multiple form Inputs (with the same name)
- From:
- Steven Kryskalla
- Date:
- 2011-06-21 @ 21:05
On Tue, Jun 21, 2011 at 4:38 PM, Santiago Basulto
<santiago.basulto@gmail.com> wrote:
> I didn't see it here: http://flask.pocoo.org/docs/api/#incoming-request-data
>
> Then i thought it didn't exist.
>
> Should i check the API that you sent in the future?
>
Hi Santiago,
The flask request and response objects are wrappers of the werkzeug
Request and Response objects, so yes, please check the werkzeug
documentation if you do not see something in the flask docs.
http://werkzeug.pocoo.org/docs/wrappers/
But, the flask documentation does point you towards werkzeug's docs
for request.form: "A MultiDict with the parsed form data from POST or
PUT requests." If you click on the link to MultiDict you will see the
same link I gave to the werkzeug docs (which shows how to use getlist,
etc.).
-Steve
Re: [flask] Get data from Multiple form Inputs (with the same name)
- From:
- Ron DuPlain
- Date:
- 2011-06-21 @ 21:04
On Tue, Jun 21, 2011 at 4:38 PM, Santiago Basulto
<santiago.basulto@gmail.com> wrote:
> Should i check the API that you sent in the future?
In general, it helps to check the Jinja and Werkzeug docs. Send doc
improvement suggestions via GitHub, irc, this mailing list, ....
-Ron