Google App Engine TextProperty и UTF-8: когда кодировать / декодировать

Я использую Google App Engine 2.5 с шаблоном Django и рамкой веб-приложения.

Db.TextProperty и UTF-8, а также Unicode и Decode / Encode меня сильно смутили. Я был бы очень признателен, если бы некоторые эксперты могли предложить некоторые предложения. Я гуглил всю ночь и у меня все еще так много вопросов.

Что я пытаюсь сделать:

[utf-8 form input] => [Python, Store in db.TextProperty] => [When Needed, Replace Japanese with English] => [HTML, UTF-8]

Согласно этому ответуСжатие строк Юникода в Python

# -*- coding: utf-8 -*-

и все файлы .py, сохраненные в формате utf-8

Вот мой код:

#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')})

Надеюсь, что какой-нибудь инженер Google App Engine сможет увидеть этот вопрос и предложить некоторую помощь. Большое спасибо!

Ответы на вопрос(2)

Ваш ответ на вопрос