I am on Google App Engine 2.5 with Django Template and Webapp Frame.
The db.TextProperty and UTF-8 and Unicode and Decode/Encode have confused me so much. I would really appreciate some experts can offer some suggestions. I have googled for the whole night and still have so many questions.
What I am trying to do:
[utf-8 form input] => [Python, Store in db.TextProperty] => [When Needed, Replace Japanese with English] => [HTML, UTF-8]
According to this answer Zipping together unicode strings in Python
# -*- coding: utf-8 -*-
and all .py files saved in utf-8 format
Here is my code:
#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')})
Hope some Google App Engine engineer can see this question and offer some help. Thanks a lot!