On Tue, Apr 17, 2012 at 09:13:33AM -0700, Michael Gimbel wrote:
> I'm encountering MakoRenderingException and UnicodeDecodeError
> exceptions throughout my application when trying to render utf8 data
> which was originally user input.
> 
> There don't seem to be Pyramid configuration options for Mako's
> output_encoding='utf-8', encoding_errors='replace'.
> 
> Python/Mako magic doesn't seem to be doing it either, ## -*- coding:
> utf-8 -*-
> 
> I've tried using a mako filter, which helped: mako.default_filters =
> decode.utf8 (in .ini file)
> But I still have problems anywhere I'm using filters or functions in
> my templates: ${var_with_utf8_chars | custom_filter}
> This seems to fix it but I don't want to have to do this throughout
> the entire application: ${var_with_utf8_chars.decode('utf8') }
> custom_filter}
> 
> I was thinking if the above is the only way, the best place to do it
> would be at the model level when the utf8 data is loaded out of the
> database.  But I was hoping for a better, more magical solution.

Decoding UTF-8 data into Unicode objects at the model level _is_ the
better solution.  E.g. SQLAlchemy can do that seamlessly.

Marius Gedminas
-- 
Never trust a smiling Gates.

Attachment: signature.asc
Description: Digital signature

Reply via email to