パイロンを使用していますが、一部の URL に次のような英語以外の文字が含まれています。
http://localhost:5000/article/111/文章标题
ほとんどの場合、問題にはなりませんが、私のログイン モジュールでは、ユーザーがログアウトした後、referer
から を取得してrequest.headers
、その URL にリダイレクトしようとします。
if user_logout:
referer = request.headers.get('referer', '/')
redirect(referer)
残念ながら、URL に英語以外の文字が含まれていて、IE のブラウザを使用している場合、次のようなエラーが報告されます (Firefox は問題ありません)。
WebError Traceback:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd5 in position 140: ordinal not in range(128)
View as: Interactive (full) | Text (full) | XML (full) clear this
clear this
URL: http://localhost:5000/users/logout
Module weberror.evalexception:431 in respond view
それを修正する方法があります (ただし、良くありません) urllib.quote()
。リダイレクトする前に URL を変換するために使用します。
referer = quote_path(url) # only quote the path of the url
redirect(referer)
ブラウザーが IE の場合にのみ機能し、非常に退屈なので、これは良い解決策ではありません。良い解決策はありますか?