By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

Encoding problem with web application (Paste+Mako)

P: n/a
msj
Hi

I have a problem with encoding non-ascii characters in a web
application. The application uses Paste and Mako.

The code is here: http://www.webudkast.dk/demo.txt

The main points are:

After getting some user generated input using
paste.request.parse_formvars, how should this be correctly saved to
file?

How should this afterward be read from the file, and fed correctly
into a Mako template?

Thanks.
Martin

Jun 6 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

ms*@infoserv.dk wrote:
Hi

I have a problem with encoding non-ascii characters in a web
application. The application uses Paste and Mako.

The code is here: http://www.webudkast.dk/demo.txt

The main points are:

After getting some user generated input using
paste.request.parse_formvars, how should this be correctly saved to
file?

How should this afterward be read from the file, and fed correctly
into a Mako template?
You have to know the encoding of user input and then you
can use ``input_encoding`` and ``output_encoding`` parameters
of ``Template``. Mako internally handles everything as Python unicode
objects.
For example:

t = Template(filename="templ.mako", input_encoding="iso-8859-2",
output_encoding="iso-8859-2")
content = t.render(**context)

--
HTH,
Rob

Jun 6 '07 #2

P: n/a
Rob Wolfe wrote:
>
You have to know the encoding of user input and then you
can use ``input_encoding`` and ``output_encoding`` parameters
of ``Template``. Mako internally handles everything as Python unicode
objects.
For example:

t = Template(filename="templ.mako", input_encoding="iso-8859-2",
output_encoding="iso-8859-2")
content = t.render(**context)

--
HTH,
Rob
Thanks Rob

Using:

t=Template(content,input_encoding="utf-8", output_encoding="utf-8")

did the trick. Thanks for the help.

/Martin
Jun 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.