Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python2.7,Appengine数据存储;统一码_Python_Google App Engine_Unicode_Utf 8 - Fatal编程技术网

Python2.7,Appengine数据存储;统一码

Python2.7,Appengine数据存储;统一码,python,google-app-engine,unicode,utf-8,Python,Google App Engine,Unicode,Utf 8,所以今晚我读了很多关于Unicoding的书,因为我想切换到Jinja2,它要求Unicode在应用程序中的任何地方都使用。我想我对如何处理它有一个很好的想法,但在我开始编写应用程序之前,我想知道这是否合理: 处理外部文本输入(通过html表单) a) 确保所有html页面都是utf-8编码的。 b) 一旦用户按下submit,确保python后端一收到数据就将其转换为Unicode…decode(self.request.get('stuff'),utf-8) c) 保持unicode,将输出

所以今晚我读了很多关于Unicoding的书,因为我想切换到Jinja2,它要求Unicode在应用程序中的任何地方都使用。我想我对如何处理它有一个很好的想法,但在我开始编写应用程序之前,我想知道这是否合理:

  • 处理外部文本输入(通过html表单)

    a) 确保所有html页面都是utf-8编码的。
    b) 一旦用户按下submit,确保python后端一收到数据就将其转换为Unicode…decode(self.request.get('stuff'),utf-8)
    c) 保持unicode,将输出传输到Jinja2,Jinja2将始终使用默认的utf-8编码

  • 来自appengine数据存储的信息

    因为谷歌把所有东西都存储为Unicode,所以从数据存储中输入的所有数据都已经是Unicode了,我不必担心任何事情(耶!)

  • 应用程序中的字符串

    确保所有“”都以u开头(即u“hello world”),这将强制所有内容都使用unicode

  • 以上是我保持一切一致的策略。还有什么我需要解释的吗


    谢谢

    如果您使用webapp或webapp2,则不需要.decode(self.request.get('stuff')、utf-8。框架尊重指定的数据输入类型

    其他一切看起来都很好

    我也相信

    from __future__ import unicode_strings
    
    应该是

    from __future__ import unicode_literals
    

    并且只在2.6和2.7版本中可用,所以在应用程序引擎中,只有当您使用2.7

    以确保从html页面获取所有unicode格式的内容时,才可以使用html字符集utf-8。在每个python代码中,确保在顶部声明了utf-8。若您这样做,您就可以了。若您使用javascript,它也会使用unicode!您也可以使用来自未来导入unicode字符串的
    ,这样带引号的字符串是unicode,没有前缀
    u
    。嘿,Philipp,我尝试了unicode字符串..但它给了我一个错误。来自未来导入unicode字符串,同样有效吗?