Does the order of elements in a GET or POST dictionary change? Django

I'm just wondering if the order of the elements in the GET or POST dictionary has changed?

if you have a list of 3 people and you say:

template:

 for x in listof3people:
    <input type="hidden" name="x.name">
    <input type="number" name="birthday">

      

in views when you do getlist (name) the order of information never changes correctly?

so if the request pulled the label, mindy and sam in that order, the get list will always show:

celebrate his birthday, memory and her birthday, and himself and his birthday in that order. The reason I am asking is because I will need to link information by position, so find the position "bar" and pull the data in the list of sockets that are in the same position.

+3


source to share


2 answers


Behind the scenes, the class QueryDict

used for GET

and POST

is built on the output six.moves.urllib.parse.parse_qsl

. This is based on the standard function urllib.parse_qsl

you can see from the source, keeping the order given in the url:

https://github.com/python/cpython/blob/a54346b3a1232cdd503abc4d4e9e526ba65b26b3/Lib/urllib/parse.py

Such inputs should be placed in the URL / encoded form data in the same order they appear in the document: Do browsers keep the order of inputs with the same name in GET / POST?



Note that I am only talking about a few values ​​for the same key, retrieved with getlist

. QueryDict

does not guarantee the order of dict keys any more than any other dict

-derived class .

So it's possible, but personally I would pass an unambiguous identifier rather than relying on it.

+1


source


I think you are talking about QueryDict . It is a custom Python dictionary. There is usually no guarantee that keys are always displayed in the order in which they are inserted. So, for your purpose, you can use some additional weight values ​​in your form so that you can order the input data according to those values.



0


source







All Articles