Reputation: 1944
As per subject, I am receiving a POST request. I want to convert it to the equivalent GET request and pass it to a template (so I can use it as href target in click-to-sort column headers).
Is there a pre-baked way to do it, or do I need to roll my own?
Cheers, alf
UPDATE
This is what I eventually used. I needed request.REQUEST, so request.POST.urlencode was not cutting it, and request.REQUEST does not have urlencode.
import urllib
def buildqs(request):
"Builds a GET-style query string form http-request"
#also request.POST.urlencode is possible -
#Sadly, request.REQUEST does not have urlencode
return urllib.urlencode(request.REQUEST)+"&"
Upvotes: 6
Views: 6970
Reputation: 38382
Use the standard library, urllib.urlencode
. e.g.
>>> import urllib
>>> urllib.urlencode({'a': 1, 'b': 2})
'a=1&b=2'
Upvotes: 7