Prepare accented characters for HTML

Antoon Pardon antoon.pardon at vub.be
Thu Mar 28 06:19:33 EDT 2019


On 28/03/19 10:38, Tony van der Hoff wrote:
> Hi,
>
> I have a MariaDB database, which contains accented (mostly French)
> characters. I need to display these on an HTML page. I'm using the Jinja
> templating engine.
>
> So, for instance, é needs to be replaced by é and so on. I've had
> some success using string.replace(), but it is difficult to cater for
> every case.

How about this function (python3):

def char2html(l):
    return '&#%d;' % ord(l)

-- 
Antoon Pardon





More information about the Python-list mailing list