2012-12-07 88 views
0

我正在寻找使用Flask的url_for来为标记生成URL--不过它似乎正在用实体/网址代码'%2B'替换'+'。这使得一个相当丑陋的网址,'+'将是首选。Python/Flask/Jinja url_for formatting

所以,我的问题是,我怎样才能使用url_for - 但让它接受'+'而无需格式化为HTML实体?

回答

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) 

所以可能是这里你可以做一些改变。