Parsing a list of dictionaries passed as a POST parameter

Posted by andyashton on Stack Overflow See other posts from Stack Overflow or by andyashton
Published on 2010-06-16T20:20:04Z Indexed on 2010/06/16 20:22 UTC
Read the original article Hit count: 302

Filed under:
|
|
|
|

I have a list of python dictionaries that look like this:

sandwiches = [
    {'bread':'wheat', 'topping':'tomatoes', 'meat':'bacon'},
    {'bread':'white', 'topping':'peanut butter', 'meat':'bacon'},
    {'bread':'sourdough', 'topping':'cheese', 'meat':'bacon'}
]

I want to pass this as a POST parameter to another Django app. What does the client app need to do to iterate through the list?

I want to do something like:

for sandwich in request.POST['sandwiches']:
    print "%s on %s with %s is yummy!" % (sandwich['meat'], sandwich['bread'], sandwich['topping'])

But I don't seem to have a list of dicts when my data arrives at my client app.

© Stack Overflow or respective owner

Related posts about python

Related posts about django