加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python 2.7,Appengine Data Store和Unicode

发布时间:2020-12-20 13:26:56 所属栏目:Python 来源:网络整理
导读:因此我今晚一直在阅读关于Unicoding的一些内容,因为我正在考虑切换到Jinja2,这需要在应用程序的各个地方使用Unicode.我想我对如何处理它有一个很好的想法,但我想在开始编写我的应用程序之前听到这是否合理: Dealing with External Text-Inputs (via html fo
因此我今晚一直在阅读关于Unicoding的一些内容,因为我正在考虑切换到Jinja2,这需要在应用程序的各个地方使用Unicode.我想我对如何处理它有一个很好的想法,但我想在开始编写我的应用程序之前听到这是否合理:

  1. 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.

    ??> appengine数据存储区中的信息
    ??
    ??

    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!)

    ??>应用程序中的字符串
    ??
    ??

    Make sure all “” start with a u (i.e. u”hello world”),this will force everything to be in unicode.

    ??

    以上是我保持一致的策略.还有什么我需要考虑的吗?

    谢谢!

解决方法

如果使用webapp或webapp2,则不需要.decode(self.request.get(‘stuff’),utf-8.框架遵循指定的数据输入类型.

其他一切看起来都很正确.

我也相信

from __future__ import unicode_strings

应该

from __future__ import unicode_literals

并且仅在2.6和2.7中可用.因此,在App Engine中,只有在使用2.7时才可用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读