Django request.POST dictionary order from the client side to the server side

django, python

Solution

For those who are asking why you'd need to rely on the order of the fields - there are cases. In my case, I was accepting a PayPal IPN, which required the data to be hashed in a correct order for the response.

Anyway, this was my original question: Retrieve POST data in the order they were sent in in Django

You can basically use HttpRequest.body (this was called `raw_post_data` in 1.4 and below). However - remember that it is up to the browser to send the data, and I don't know whether browsers guarantee order of the form fields when you submit the form.

Problem

Can someone point me in the right direction. Essentially, I have a `<form>` that has a variable number of fields: ``` <input value="1" name="cat"> <input value="2" name="dog"> <input value="3" name="tiger"> ``` When I look at the `request.POST`, the dictionary order is off: ``` {'dog':['2'], 'cat':[1], 'tiger':['3']} ``` I realize that dictionary ordering is not maintained within Python - however I need a way to get that ordering back on the backend. How could I go about doing this? My first idea is using JS, but I was hoping there would be a better way.

Original source

Related problems