In the unicode() call you must specify the encoding used, to decode
the string to a unicode one. Or pass it a unicode string.
example unicode(s,'utf-8')

The Django code uses the default encoding string ascii.

Or make a list of objects with a __unicode__() method that returns the
unicode version of the string.

You could build your choices list with unicode strings

 _CHOICES_FORMATION = (
     unicode('Administração','latin_1'),
     unicode('Design Gráfico','latin_1'),
     unicode('Jornalismo','latin_1'),
     unicode('Marketing','latin_1'),
     unicode('Outras','latin_1'),
 )
Or use the encoding name that is used to edit the file.

2011/1/18 Josir <[email protected]>:
> Thanks for replying Zeynel.
>
> I've read this article before but I could not understand how can it
> help me because it does not have any citation on Django or GA.
>
> Usually, in pure Python/Django, I use the u' notation and forms and
> templates understand that the string is unicode.
> But on GA, it's not working.
>
> Do you have any specific suggestion/tip on the above code ?
>
> Josir Gomes
>
> On Jan 18, 2:23 am, Zeynel <[email protected]> wrote:
>> Can this be helpful to 
>> youhttp://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror
>>
>> On Jan 17, 10:53 pm, Josir <[email protected]> wrote:
>>
>> > Hi folks, I have the following code:
>>
>> > _CHOICES_FORMATION = (
>> >     'Administração',
>> >     'Design Gráfico',
>> >     'Jornalismo',
>> >     'Marketing',
>> >     'Outras',
>> > )
>>
>> > class Contact(db.Model):
>> >     name = db.StringProperty(verbose_name='Nome', required=True)
>> >     email = db.EmailProperty(verbose_name='E-mail', required=True)
>> >     phone = db.StringProperty(verbose_name='Telefone')
>> >     formation = db.StringProperty(
>> >         verbose_name=u'Formação',
>> >         choices=_CHOICES_FORMATION,
>> >         default=_CHOICES_FORMATION[0])
>>
>> > When I try to run it, I got
>>
>> >   File "/home/josir/sist/google_appengine/google/appengine/ext/db/
>> > djangoforms.py", line 170, in get_form_field
>> >     choices.append((str(choice), unicode(choice)))
>> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
>> > 10: ordinal not in range(128)
>>
>> > To fix it, I tried:
>>
>> > 1)    u'Administração',
>>
>> > 2)   insert the header:
>>
>> > #!/usr/bin/env python
>> > # -*- coding: utf-8 -*-
>> > # coding=utf-8
>>
>> > But both solution didn't work. How can I use latin (portuguese)
>> > characters on choice field ?
>>
>> > Thanks in advance,
>> > Josir.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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/google-appengine?hl=en.

Reply via email to