URL和request.query_string中的空格将在输出中返回%20

时间:2018-09-11 21:33:12

标签: url flask urllib request.querystring

我需要访问问号后的句子,例如follow(我正在使用flask和python):

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

我使用以下代码:

query_string = request.query_string

我知道URL中不允许使用空格,但是有没有办法我可以再次将%20解码为空格?

1 个答案:

答案 0 :(得分:0)

您可以为此使用python的标准库。

Python3:

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

Python2

import urllib
urllib.unquote(request.query_string)