【问题标题】:White spaces in the URL and request.query_string will return %20 in the outputURL 和 request.query_string 中的空格将在输出中返回 %20
【发布时间】:2018-09-11 21:33:11
【问题描述】:

我需要像下面这样访问问号后的句子(我正在使用flask和python):

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

我使用以下代码:

query_string = request.query_string

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

【问题讨论】:

    标签: url flask urllib request.querystring


    【解决方案1】:

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

    Python3:

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

    Python2

    import urllib
    urllib.unquote(request.query_string)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2014-08-08
      • 1970-01-01
      • 2014-08-19
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多