url_encode
在 Werkzeug 3.0 中不再可用。
将其替换为
urlencode
中的 urllib.parse
不适用于列表,例如
>>> from werkzeug.datastructures import MultiDict
>>> from urllib.parse import urlencode
>>> d = MultiDict(('a', '1'), ('a', '2'))
>>> urlencode(d) #werkzeug url_encode returned 'a=1&a=2'
'a=1'
如何在 Werkzeug 3.0 中对
MultiDict
进行 url 编码,以便我可以将其用作 x-www-form-urlencoded
数据?
发现自己的不太直观直接答案:
>>> from werkzeug.datastructures import MultiDict
>>> from urllib.parse import urlencode
>>> d = MultiDict(('a', '1'), ('a', '2'))
>>> urlencode(d.to_dict(flat=False), doseq=True)
'a=1&a=2'