Google App Engine TextProperty y UTF-8: cuándo codificar / decodificar
Estoy en Google App Engine 2.5 con Django Template y Webapp Frame.
La db.TextProperty y UTF-8 y Unicode y Decode / Encode me han confundido tanto. Realmente agradecería que algunos expertos puedan ofrecer algunas sugerencias. He buscado en Google durante toda la noche y todavía tengo muchas preguntas.
Lo que estoy tratando de hacer:
[utf-8 form input] => [Python, Store in db.TextProperty] => [When Needed, Replace Japanese with English] => [HTML, UTF-8]
De acuerdo con esta respuestaComprimiendo cuerdas Unicode en Python
# -*- coding: utf-8 -*-
y todos los archivos .py guardados en formato utf-8
Aquí está mi código:
#Model.py
class MyModel(db.Model):
content = db.TextProperty()
#Main.py
def post(self):
content=cgi.escape(self.request.get('content'))
#what is the type of content? Unicode? Str? or Other?
obj = MyModel(content=content)
#obj = MyModel(content=unicode(content))
#obj = MyModel(content=unicode(content,'utf-8'))
#which one is the best?
obj.put()
#Replace one Japanese word with English word in the content
content=obj.content
#what is the type of content here? db.Text? Unicode? Str? or Other?
#content=unicode(obj.content, 'utf-8') #Is this necessary?
content=content.replace(u'ひと',u'hito')
#Output to HTML
self.response.out.write(template.render(path, {'content':content})
#self.response.out.write(template.render(path, {'content':content.encode('utf-8')})
Espero que algún ingeniero de Google App Engine pueda ver esta pregunta y ofrecer alguna ayuda. ¡Muchas gracias!