I need to get the query string from this URL https://stackoverflow.com/questions/ask?next=1&value=3 and I don't want to use request.META. I have figured out that there are two more ways to get the query string:
Using urlparse urlparse.urlparse(url).query
Using url encode Use urlencode and pass the request.GET params dictionary into it to get the string representation.
So which way is better? My colleagues prefer urlencode but have not provided a satisfying explanation. They claim that urlparse calls urlencode internally which is something I'm not sure about since urlencode lives in the urllib module.
I prefer using
From docs:
https://docs.djangoproject.com/en/stable/ref/request-response/#django.http.HttpRequest.META
This does not include the
?
prefix.you can also use request.arg also
Third option:
In Python 3+ this is available as:
Documentation for urllib.parse
You can make Query string using GET parameters like this
This does not include the
?
prefix, and it may not return the keys in the same order as in the original request.