The problem is in your __str__() function, because Python 2 use
__unicode__() instead of str to return Unicode string. By default p2 return
bytes in __str__ and p3 return Unicode.

python_2_unicode_compatible works and I thing it is the best approach
because you are support both version 3/2 .

I recommend use Python 3 because has less problems with non-ascii
characters, but p2 it's OK too.



El domingo, 6 de marzo de 2016, Georges H <[email protected]>
escribió:
> OK thanks
> Without the python_2_unicode_compatible decorator before my class, it
does not work.
>
> Le dimanche 6 mars 2016 14:11:41 UTC+1, Vijay Khemlani a écrit :
>>
>> Do you know why you had the problem in the first place or are you just
copy-pasting code?
>> If you only need to support one version of Python (either 2.x or 3.x)
there is no need to use the python_2_unicode_compatible decorator
>> On Sun, Mar 6, 2016 at 8:14 AM, Georges H <[email protected]> wrote:
>>>
>>> OK Thanks but I solved this little problem by adding at the top of my
models.py:
>>> django.utils.encoding import from python_2_unicode_compatible
>>>
>>>
>>> And always in models.py before each class:
>>> @ python_2_unicode_compatible
>>> Perfect!
>>> Le dimanche 6 mars 2016 03:16:35 UTC+1, Vijay Khemlani a écrit :
>>>>
>>>> The error you are seeing is at the application level, not database, so
I don't think postgres is at fault.
>>>> Post the full stack trace for the error and the relevant part of your
code when it fails.
>>>> On Sat, Mar 5, 2016 at 3:28 PM, Georges H <[email protected]> wrote:
>>>>>
>>>>> Hi to all the Django community !
>>>>> I started with Django.
>>>>> I have a small form that works pretty well, and that will store the
data in a Postgres database, that's fine.
>>>>> OK, except that when I have a special character to enter (like an
accent, I am french), I get an error (No problem without special
characters):
>>>>> 'Ascii' codec can not encode character u '\ xe9' in position 0:
ordinal not in range (128)
>>>>> Yet I thought the default Django was utf8...
>>>>> So I tried to add in settings.py:
>>>>> LANGUAGE_CODE = 'en-us'
>>>>> LANG = 'UTF-8'
>>>>> LC_ALL = 'UTF-8'
>>>>> DEFAULT_CHARSET = 'utf-8'
>>>>> But it does not change ...
>>>>> I notice that if my base postgres is encoded in UTF-8 (when I do a
"SHOW SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW
CLIENT_ENCODING").
>>>>> Is it linked?
>>>>> I also notice that the "local" command at the root of my Django
project returns me:
>>>>> LANG = en_US.UTF-8
>>>>> LC_CTYPE = "en_US.UTF-8"
>>>>> LC_NUMERIC = "en_US.UTF-8"
>>>>> LC_TIME = "en_US.UTF-8"
>>>>> LC_COLLATE = "en_US.UTF-8"
>>>>> LC_MONETARY = "en_US.UTF-8"
>>>>> LC_MESSAGES = "en_US.UTF-8"
>>>>> LC_PAPER = "en_US.UTF-8"
>>>>> Lc_name = "en_US.UTF-8"
>>>>> LC_ADDRESS = "en_US.UTF-8"
>>>>> LC_TELEPHONE = "en_US.UTF-8"
>>>>> LC_MEASUREMENT = "en_US.UTF-8"
>>>>> LC_IDENTIFICATION = "en_US.UTF-8"
>>>>> LC_ALL =
>>>>> With "LC_ALL" empty !!! So it is that I did not understand where to
put this setting...
>>>>> How can I force Django to operate only in UTF-8? Or another approach?
>>>>>
>>>>> THX!
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b9b18216-e21f-4195-8ae3-b3cfbed70c31%40googlegroups.com
.
>>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/d17cffcc-d595-485c-8203-ad8dfaeb7412%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyM1sq7bcSZAemHUK3TcGm-D-L4A3sU0dsDSjr_5fxFZag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to