I have a list object that I’m sending to a script using CGI. The list is being sent using a hidden field in an HTML form. When I extract the object in the receiving script using my_list = form.getlist[‘name_of_hidden_field’], the list is stored as a single large text string in the first element of my_list rather than the list I want. What am I doing wrong?
# snippet of code from the script with the HTML
my_list = ['string1', 'string2', 'string3]
print '<form name="input" action="my_script.py">'
print '<input type="hidden" name="my_list" value="%s">' % (my_list,)
print '<input type="submit" name="submit" value="Submit" />'
print "</form>"
# snippet of code from my_script.py
my_list = form.getlist('my_list')
# what I'm seeing in my_script.py
>>>print my_list
["['string1', 'string2', 'string3']"]
Thanks for your advice.
You need to send the list as a bunch of different
inputs with the same name forgetlistto get the elements: