Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML)

Chris Angelico rosuav at gmail.com
Fri Mar 29 07:08:15 EDT 2019


On Fri, Mar 29, 2019 at 9:12 PM Tony van der Hoff <lists at vanderhoff.org> wrote:
>
> Hello Chris.
> Thanks for your interest.
>
> On 28/03/2019 18:04, Chris Angelico wrote:
> > On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff <lists at vanderhoff.org> wrote:
> >>
> >> This'll probably work:
> >
> > You have a python3 shebang, but are you definitely running this under Python 3?
> >
> Absolutely.
>
> > Here's a much more minimal example. Can you see if this also fails for you?
> >
> > import sys
> > from jinja2 import Template
> > print(Template("French: {{french}}").render({"french": "année"}))
> > print(sys.version)
> >
>
> Presumably you expect to run this from the command line. It works as
> expected:
>
> French: année
> 3.5.3 (default, Sep 27 2018, 17:25:39)
> [GCC 6.3.0 20170516]
>
> However, with a slight modification:
>
> #!/usr/bin/env python3
>
> import sys
> from jinja2 import Template
> print ("Content-type: text/html\n\n")

Try: text/html; charset=utf-8

That might be all you need to make the browser understand it
correctly. Otherwise, as Thomas says, you will need to figure out
where the traceback is, which can probably be answered by figuring out
what "running it in a browser" actually means.

ChrisA



More information about the Python-list mailing list