4

There are lots of question discussing how to get 1 parameter, but how do you get all of the parameters, preserving their order?

There's this way: request.GET.get('q', '') to get 1 parameter.

I need to capture POST requests to my URL, then add a parameter to the URL, and send it right back to confirm it's validity and source. This is for PayPal IPN if you're wondering.

Thanks!

ruddra
  • 50,746
  • 7
  • 78
  • 101
User
  • 23,729
  • 38
  • 124
  • 207

3 Answers3

5

As @Daniel Roseman said you probably don't need to preserve the order, in which case you can just use the request.GET dict

Alternatively you can get the raw querystring:

request.META['QUERY_STRING']

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META

Anentropic
  • 32,188
  • 12
  • 99
  • 147
1

As Daniel Roseman mentions, order should not be significant between POST or GET request parameters; think of them like key-value pairs rather than a list.

If you want to maintain order, then perhaps pass a list as the value in your POST and grab it in Django:

myData = request.POST.get("myQuery")

Specifically, POST requests don't use the querystring* (see here). POSTs use the request body while GETs use the query string. Note that security-wise, this also means important client information isn't blatantly displayed in the URL -- which is especially important when dealing with payments.

Update: *Apparently, POSTs can use the query string, but they really shouldn't. See this SO post for more.

Community
  • 1
  • 1
Casey Falk
  • 2,617
  • 1
  • 18
  • 29
0

paypal ipn

Yes, order is significant here. This is what I'm going to use:

newParameteres = 'cmd=_notify-validate&' + self.request.POST.urlencode()
req = urllib2.Request("http://www.paypal.com/cgi-bin/webscr", newParameteres)
User
  • 23,729
  • 38
  • 124
  • 207
  • urllib2 is not part of Python3. Any change that you know how to achieve this today? I am having the same struggle right now... – Ryan Pergent Jul 27 '18 at 10:15