django passing post variables -


i'm doing dynamic form javascript in django template. number of inputs depends of number of points user had made in map. when try inputs in view, i've got them disordered. when see post variables debug, variables arranged. idea?

template.html

 function getcoordinates(){                                  var = 0             form = document.getelementbyid('frm');                   (var i=0; i<points_l.length; i++){                inp=document.createelement('input');             inp.type='hidden';             inp.value=coord_l[i].lon+","+coord_l[i].lat;//setattribute('value',coord_l[i]);             inp.id='inp_'+i;             inp.name = 'inp_'+i;             form.appendchild(inp);                                       }          form.submit();               } 

views.py

for k, v in request.post.iteritems():      if k.startswith('inp'):         elems = v.split(',')         lon = ''.join(elems[-1:])         lat = ''.join(elems[:-1])         coordinates_l.append(lat)         coordinates_l.append(lon)  

if have 5 inputs, loop inputs in order: inp_3, inp_4, inp_5, inp_1, inp_2. need inputs in order!

thanks!

i don't know order can sort request.post dict (standard python dicts don't have order) this:

for k, v in sorted(request.post.iteritems()):     if k.startswith('inp'):         elems = v.split(',')         lon = ''.join(elems[-1:])         lat = ''.join(elems[:-1])         coordinates_l.append(lat)         coordinates_l.append(lon) 

hope helps.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -