Python 2.7, Appengine Data Store and Unicode

So, today I read a little about Unicoding, because I was thinking of switching to Jinja2, which requires the use of Unicode throughout the application. I think I have a good idea how to deal with this, but I wanted to hear if it is reasonable before I started coding my application:

  • Work with external text inputs (via html-forms)

    a) Make sure that all html pages are encoded in utf-8.
    b) After users click submit, make sure the data is converted to Unicode as soon as the python backend receives it ... decode (self.request.get ('stuff'), utf-8)
    c) Remain unicode, port the outputs to Jinja2, which will always use the default utf-8 encoding.

  • Information from the appengine datastore repository

    Since google stores everything as Unicode, all the data coming from the data store is already unicode and I don’t have to worry about anything (yay!)

  • Application Lines

    Make sure everyone "starts with u (i.e. u" hello world "), this will make everyone be unicode.

It's good that this is my strategy so that everything is agreed. Is there anything else I need for accounting?

thanks!

+4
source share
1 answer

You do not need to use .decode (self.request.get ('stuff'), utf-8 if you are using webapp or webapp2. The structure matches the type of data input as indicated.

Everything else looks right.

I also believe that

from __future__ import unicode_strings 

it should be

 from __future__ import unicode_literals 

and is available only in versions 2.6 and 2.7. Thus, in App Engine, it will only be available if you are using 2.7

+1
source

Source: https://habr.com/ru/post/1400542/


All Articles