How to store dynamically generated HTML form elements from Javascript in Python?

I have an HTML form where a user can add an arbitrary number of input fields in jQuery. The user can also remove any input field from any position. My current implementation is that each new input field has an identifier "field [i]", so when the form is posted, it is processed in Python as field1, field2 field3, ... field [n]

i = 0
while self.request.get("field" + str(i)):
        temp = self.request.get("field" + str(i))
        someList.append(temp)
        i += 1

      

(Let's assume JavaScript handles deleting deleted items and sorting the field names before posting for simplicity)

This approach works for me, but is there a better way to handle this situation? I feel like this is very brute force.

Platform Information: Python 2.5.4; JavaScript; DHTML; JQuery; Google App Engine

Edit: It looks like self.request.get_all () was the solution: GAE Doc p>

+2


source to share


1 answer


You can serialize data using javascript and pass it as json. Then you only have a dictionary to work with python. You will need something like simplejson of course



+1


source







All Articles