Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Convert a POST request parameters to query string

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)+"&"
like image 903
Alien Life Form Avatar asked Apr 08 '11 08:04

Alien Life Form


1 Answers

Use

request.POST.urlencode()
like image 72
mossplix Avatar answered Sep 18 '22 01:09

mossplix