2012-12-07 89 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) 

所以可能是這裏你可以做一些改變。