git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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