Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask nested post data

Tags:

python

flask

I'm trying to build in a way to handle a large number of posted options, e.g.

my_posted_data = {"item": "value", "item_options":{"a":2, "b":2} }

This would be coming from somewhere else in an api situation where I'm not in control of the environment and it is simulated for now. I'll post that through the requests library; and moving server-side, I try to get this from the route/view in my application. request.form gets read into a variable(form) which is passed to a task_manager queue. In the task I'll try to do:

options = form.get("item_options", None)

options always ends up as NoneType. Why is this not selecting the dict(like) value of {"a": 2, "b": 2}? I guess I'm doing it wrong, but what at this point I am unable to pinpoint.

Based on this scant picture I've provided, how do I post and and retrieve nested values with Flask request in the most effective way?

EDIT: I had to go a different way, using JSON data because I realized for the situation that is best, the form is more for user input from an html page, and this is something that requires a different approach.

like image 880
blueblank Avatar asked Oct 21 '25 14:10

blueblank


1 Answers

By using Flask-WTF with Field Enclosures in WTForms, you can easily handle nested post data.

like image 56
hdang Avatar answered Oct 24 '25 04:10

hdang