2017年12月13日

self.redirectに全角を渡す場合

Google App Engine
webapp2のredirectについて
Pythonの場合


webapp2.recirectはstrを受け付ける

unicodeは受け付けない

unicodeを渡す場合はunicodeをutf-8でエンコードしてurlエスケープしてformatに渡して出来上がったものをwebapp2.redirectに渡す




aa = u'あ'
(aaはunicode)
self.redirect('{0}'.format(urllib.quote(aa.encode('utf-8'))))



参考
webapp2.request.get()
<type 'unicode'>

type(u'あ')
<type 'unicode'>

type('あ')
<type 'str'>

type(u'あ'.encode('utf-8'))
<type 'str'>