【问题标题】:Redirect to a page with a Japanese character parameter using webapp2使用 webapp2 重定向到带有日语字符参数的页面
【发布时间】:2012-12-05 18:55:46
【问题描述】:

在我的网络应用程序中,我想从 POST 重定向到 GET 到另一个 URL,并将 GET 的参数设置为日语字符。

这行得通:

self.redirect("SomePage?param=%s" % "value")

这会在重定向中引发编码错误:

self.redirect("SomePage?param=%s" % u"が")

有没有办法为重定向页面重定向和设置日语字符参数?

【问题讨论】:

  • 你到底得到了什么错误?堆栈跟踪?如果你试试self.redirect("SomePage?param=%s" % u"が".encode('utf_8')
  • 那么它根本不会重定向到任何地方。它也不会引发错误。

标签: python redirect unicode webapp2


【解决方案1】:

查询字符串应编码为'utf-8'和percent-encoded:

>>> import urllib
>>> 'SomePage?%s' % urllib.urlencode({'param': u'が'.encode('utf-8')})
'SomePage?param=%E3%81%8C'

【讨论】:

    猜你喜欢
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 2011-07-04
    • 2015-07-26
    • 1970-01-01
    • 2020-10-29
    • 2013-09-12
    相关资源
    最近更新 更多