Search code examples
urlflaskurllibrequest.querystring

White spaces in the URL and request.query_string will return %20 in the output


I need to have access to the sentence after question mark like follow(I am using flask and python):

http://localhost:8000/answer?the new book is added

I use the following code:

query_string = request.query_string

I know that white spaces are not allowed in the URLs but is there a way that I can decode the %20 to the white spaces again?


Solution

  • You can use python's standard library for that.

    Python3:

    import urllib.parse
    urllib.parse.unquote(request.query_string)
    

    Python2

    import urllib
    urllib.unquote(request.query_string)