Have you tried writing

# coding: utf-8

on top of your code?

On Sep 24, 5:30 pm, Eduardo Robles Elvira <[email protected]> wrote:
> Hello everyone,
>
> I'm trying to create a webpy form that when rendered will contain some
> unicode characters like Ñ or áéíóú (I'm spanish). I'm having problem
> with that, and I'm also having trouble when receiving the post data
> from the form, again when the data contains those characters. This is
> some sample code:
>
> from __future__ import unicode_literals
> ...
>
> provinces_states = {"Álava" : "País Vasco", ... }
>
> form = web.form.Form(web.form.Textbox('username', name_regexp,
> description=_('Username')),
>         form.Dropdown('province',
>             [(decode_str(key), decode_str(key)) for key in
> sorted(provinces_states.iterkeys())],
>             description=_("Your province")),
> )
>
> Then simply get a view to render that. It fails:
>
>   File "/media/home/edulix/proyectos/kurusoft/opengnsys/web/user/
> login.py", line 87, in GET
>     return web.ctx.normal_render.user.login(self.form)
>   File "/media/home/edulix/proyectos/kurusoft/opengnsys/web/web/
> template.py", line 899, in __call__
>     return BaseTemplate.__call__(self, *a, **kw)
>   File "/media/home/edulix/proyectos/kurusoft/opengnsys/web/web/
> template.py", line 805, in __call__
>     return self.t(*a, **kw)
>   File "templates/user/login.html", line 18, in __template__
>     </div>
>   File "/media/home/edulix/proyectos/kurusoft/opengnsys/web/web/
> form.py", line 44, in render
>     out += '    <tr><th><label for="%s">%s</label></th><td>%s</td></tr>
> \n' % (i.id, net.websafe(i.description), html)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 151: ordinal not in range(128)
>
> Also, if for example the received web.input().username contains
> unicode characters, the same kind of errors. Can someone enlighten me,
> please?
>
> Regards,
>    Eduardo Robles Elvira.

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" 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/webpy?hl=en.

Reply via email to