librelist archives

« back to archive

Nesting Post Data

Nesting Post Data

From:
blueblank
Date:
2012-08-10 @ 19:40
I'm working on an api, where I have one route that takes posted data and
will return processed information. It works on a model, basically calling a
method on that model from a 'return_request' sent with the post, which has
been working well so far for development.

Now, I want to add a posted field that can contain options that I can
process and pass as arguments to the model methods e.g.:

{"return_request":"hello", options: { "worlds": 3} }

and when posted to the view, the view can take that and call

model.hello(3)

and send back "hello world, hello world, hello world"

some more context:
http://stackoverflow.com/questions/11894331/flask-nested-post-data

Without really providing any detailed code examples, everything I've done
is telling me that I'm doing this wrong. I can't seem to send or get that
field properly(its always empty or just says 'worlds' e.g.), so I'm not
sure what I'm doing wrong at this point. Is this making any sense? I just
want to pass in text or a dict or json that I pass in options for any
number of methods without having to code in checks for 50 field types. I've
tried wtforms too at this point with no more success.

This seems like a common thing, not unique, so maybe someone can help me to
understand what I'm not understanding and how to do this more effectively.

Re: [flask] Nesting Post Data

From:
Audrius Kažukauskas
Date:
2012-08-12 @ 19:25
On Fri, 2012-08-10 at 15:40:12 -0400, blueblank wrote:
> I'm working on an api, where I have one route that takes posted data and
> will return processed information. It works on a model, basically calling a
> method on that model from a 'return_request' sent with the post, which has
> been working well so far for development.
> 
> Now, I want to add a posted field that can contain options that I can
> process and pass as arguments to the model methods e.g.:
> 
> {"return_request":"hello", options: { "worlds": 3} }

Not sure if I understand this correctly, but if it's an API you're
writing and you expect structured data, why not use JSON instead of
forms?  JSON encoded data would be POSTed to your view using
application/json content type and it would be accessible from
request.json.  For validation I would recommend Colander[0], it works
great with structured data.

[0] http://docs.pylonsproject.org/projects/colander/en/latest/

-- 
Audrius Kažukauskas
http://neutrino.lt/

Unsubscribe

From:
Dave Tuttle
Date:
2012-08-13 @ 16:12
--
Dave

On Sun, Aug 12, 2012, at 12:25, Audrius Kažukauskas wrote:
> On Fri, 2012-08-10 at 15:40:12 -0400, blueblank wrote:
> > I'm working on an api, where I have one route that takes posted data and
> > will return processed information. It works on a model, basically calling a
> > method on that model from a 'return_request' sent with the post, which has
> > been working well so far for development.
> > 
> > Now, I want to add a posted field that can contain options that I can
> > process and pass as arguments to the model methods e.g.:
> > 
> > {"return_request":"hello", options: { "worlds": 3} }
> 
> Not sure if I understand this correctly, but if it's an API you're
> writing and you expect structured data, why not use JSON instead of
> forms?  JSON encoded data would be POSTed to your view using
> application/json content type and it would be accessible from
> request.json.  For validation I would recommend Colander[0], it works
> great with structured data.
> 
> [0] http://docs.pylonsproject.org/projects/colander/en/latest/
> 
> -- 
> Audrius Kažukauskas
> http://neutrino.lt/