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)


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")
print(Template("French: {{french}}").render({"french": "ann?e"}))
print(sys.version)

and running it in a browser (tried both chrome and Firefox),
it fails as before: blank web page. Replacing the accented character
displays the expected result:

French: annee 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]

Thanks to all who have pitched in. As I previously mentioned, I have a
work-around, so no big deal, but I would like to get to the bottom of this.

Cheers, Tony
-- 
Tony van der Hoff        | mailto:tony at vanderhoff.org
Buckinghamshire, England |