I have a lib/languages.py file only with a dict format e.g.:
en = {}
en["farewell"] = "goddbye"
es = {}
es["farewell"] = "Adiós"
Also I have a lib/basehandler.py where I use language.py and this basehandler has a Unicode literal (# –– coding: utf-8 ––)
The problem is that when I render a template in Spanish (es), the html has “Adi&ocuate;s” instead “Adi&oaucte;s”
I tried to use on languages.py
es["farewell"] = "Adiós"
or add Unicode literal (# –– coding: utf-8 ––), but nothing work.
Can anyone please, tell me what I’m doing wrong or what’s the best way to work with Unicode on Jinja2
Here is the source code https://github.com/coto/gae-boilerplate and if you want to see the problem http://appengine.protoboard.cl/?&hl=es
Thanks in advance
The library you’re using of jinja2 has autoescape default set to True. You may override this in your code by going to
basehandler.py, and look for these lines:Replace it with this:
I’m not sure if
environment_argsandautoescapein the additional code above need the single quotes or not. Feel free to try different variations of them.If you want to keep
autoescape Trueas the default, then you can just add|safeto each variable in your template.For example in
home.htmlbecomes
and so on…