On Jun 20, 2007, at 8:14 PM, [EMAIL PROTECTED] wrote:
>
> Hello guys, I'm trying to use mako with unicode, but I get the
> following error:
>
> mako.exceptions.CompileException: Unicode decode operation of encoding
> 'utf-8' failed in file 'foo.txt' at line: 0 char: 0
I'm not sure why you're seeing a CompileException during Unicode
decoding here (was this raised by the get_template() call?). Maybe
your editor isn't saving foo.txt as UTF-8?
What I would expect to see is a UnicodEncode error when the template
was being rendered. This is because your template contains UTF-8, but
calling render() returns raw strings (encoded as ascii). Instead you
should call render_unicode() and convert the unicode to a string (or
pass output_encoding and optionally encoding_errors parameters to
TemplateLookup). But it appears your main() function didn't even get
that far
>
> I read the mako documentation and tried the following example:
>
> # -*- coding: utf-8 -*-
>
> from mako.template import Template
> from mako.lookup import TemplateLookup
>
> def main():
> mylookup = TemplateLookup(directories=["."])
> mytemplate = mylookup.get_template("foo.txt")
> print mytemplate.render()
>
> if __name__ == "__main__":
> main()
>
> The foo.txt file is written as follows:
>
> # -*- coding: utf-8 -*-
> Jesús Antonio
>
> Any help will be very appreciated.
>
--
Philip Jenvey
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---