0

我正在寻找使用 Flask 的 url_for 为标签生成 URL - 但是它似乎正在用实体/url 代码“%2B”替换“+”。这使得 URL 相当难看,'+' 会更受欢迎。

所以,我的问题是,如何使用 url_for - 但让它接受 '+' 而不将其格式化为 HTML 实体?

4

1 回答 1

0

flask url_for 函数调用 werkzeug url_quote 函数(查看 github 上的源代码)。url_quote 函数定义为:

def url_quote(s, charset='utf-8', safe='/:'):
"""URL encode a single string with a given encoding.

:param s: the string to quote.
:param charset: the charset to be used.
:param safe: an optional sequence of safe characters.
"""
if isinstance(s, unicode):
    s = s.encode(charset)
elif not isinstance(s, str):
    s = str(s)
return _quote(s, safe=safe)

所以可能这是你可以做一些改变的地方。

于 2012-12-07T16:50:23.520 回答