Set Python27 Google AppEngine as default for whole application

I would like to set the default encoding for utf-8 for my appengine python27 site. The default is ascii.

There was a similar question: http://code.google.com/p/googleappengine/issues/detail?id=5923 . It says that you should not use sys.reload after setting the default encoding or you will lose the request.

How can I set utf-8 encoding for my entire appengine site for python, without having to encode strings, especially like the link suggested above?

Thanks for any help.

+4
source share
1 answer

You can run your python 27 code (each Python file) with

#!/usr/bin/python # -*- coding: utf-8 -*- from __future__ import unicode_literals 

But sometimes you need to use .encode ('ascii') if you use HMAC or you need to set HTTP headers. Or you can use:

 self.response.headers[str('Content-Type')] = str(content_type) 

or

  self.response.headers[b'Content-Type'] = str(content_type) 

And make sure that:

  • all your html files use utf-8
  • your editor uses utf-8 by default
+3
source

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


All Articles