【问题标题】:Whether urlencode is needed when dealing with Flask REST API?处理 Flask REST API 时是否需要 urlencode?
【发布时间】:2015-10-20 10:41:42
【问题描述】:
我有一个基于 Flask 的 Web 应用程序正在运行,我不确定以下两个 url 是否与 Flask 请求等效
www.example.com/hello?a=Hello+G%C3%BCnter
和
www.example.com/hello?a=Hello Günter
这些 url 是如何在内部翻译成 Flask 请求的?非常感谢
【问题讨论】:
标签:
url
python-3.x
flask
werkzeug
【解决方案1】:
浏览器(或任何其他 http 客户端,如 curl)在发送到服务器之前应将这两个 URL 转换为 www.example.com/hello?a=Hello+G%C3%BCnter,因为 www.example.com/hello?a=Hello Günter 不是有效的 HTTP URL。所以 Flask 在这两种情况下都会收到www.example.com/hello?a=Hello+G%C3%BCnter,并提供它来查看解码的函数参数,如"Hello Günter"。