Python 2.7,Appengine Data Store&统一 [英] Python 2.7, Appengine Data Store & Unicode
问题描述
所以我今天晚上对Unicoding有很多了解,因为我正在考虑切换到Jinja2,这需要Unicode在应用程序中的任何地方使用。我想我对如何处理它有了一个好主意,但是我想在开始编写我的应用程序之前听到这是否合理:
处理外部文本输入(通过html表单)a)确保所有的html页面都是UTF-8编码的。
b)一旦用户按下提交,确保数据一旦python后端收到它就转换为Unicode ... decode(self.request.get( 'stuff'),utf-8)
c)留在unicode中,将输出转移到Jinja2,它总是使用utf-8的默认编码。
blockquote>
来自appengine数据存储区的信息
lockquote
因为Google将所有内容存储为Unicode,所有来自数据存储区的数据都已经是unicode,我不必担心任何事情(yay!)
应用程序中的字符串
确保所有以u开头(即),这将迫使一切都在unicode。
以上是我保持一致的策略。还有什么我需要考虑的?
谢谢!
您不需要.decode self.request.get('stuff'),utf-8如果使用webapp或webapp2。框架尊重指定的数据输入类型。
其他看起来是正确的。
另外,我相信__future__中的
import unicode_strings
应该是
from __future__ import unicode_literals
仅适用于2.6和2.7所以在App Engine它只有在使用2.7
时才可用
So I've been reading quite a bit about Unicoding tonight because I was thinking of switching to Jinja2, which requires Unicode to be used everywhere within the app. I think I have a good idea of how to deal with it, but I wanted to hear if this is reasonable before I started to code my app:
Dealing with External Text-Inputs (via html forms)
a) Make sure all html pages are utf-8 encoded.
b) Once users press submit, make sure the data is converted into Unicode as soon as the python backend receives it...decode(self.request.get('stuff'),utf-8)
c) Stay in unicode, transfer the outputs to Jinja2 which will always it using the default encoding of utf-8.Information from the appengine datastore
Because google stores everything as Unicode, all data coming in from the datastore is already unicode and I don't have to worry about anything (yay!)
Strings within the app
Make sure all "" start with a u (i.e. u"hello world"), this will force everything to be in unicode.
Well the above is my strategy to keep everything consistent. Is there anything else I need to account for?
thanks!
You should not need to .decode(self.request.get('stuff'),utf-8 if you using webapp or webapp2. The framework respects the input type of the data as specified.
Everything else looks right.
Also I believe that
from __future__ import unicode_strings
should be
from __future__ import unicode_literals
and is only available in 2.6 and 2.7 So in App Engine it would only be available if you are using 2.7
这篇关于Python 2.7,Appengine Data Store&统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!