2008/10/30 Andrew <[EMAIL PROTECTED]>

>
> I am currently working through the django book and I've got to the
> fifth chapter where I would like to replace the __str__() methods with
> __unicode__() methods instead. The reason is that my database will
> hold a great deal of Japanese text, UTF-8 encoded. After declaring the
> UTF-8 encoding at the top of models.py, as a test, I replace
>
> def __str__(self):
>        return self.name
>
> with
>
> def __unicode__(self):
>    return u'テスト'
>
> Entering the following code into the manage.py shell doesn't give the
> expected output.
>
> >>> from books.models import Publisher
> >>> publisher_list = Publisher.objects.all()
> >>> publisher_list
>
> I expect:
>
> [<Publisher: テスト>, <Publisher: テスト>]
>
> but instead, the テスト is replaced with random Japanese characters that
> are not the ones I expected.
>
> I am using a Japanese version of Windows XP with PostgreSQL installed.
> The encoding of the database and the file are both UTF-8. The cmd.exe
> prompt doesn't let me type in Japanese but it does display Japanese if
> print out something I've saved in a file for example.
>
> Any ideas on where I'm going wrong?
>
>
I do not know if this will work for Japanese Windows, but for the English
version, the two things I have found that need to be done to ensure a
command prompt properly displays utf-8
are first:

chcp 65001

in the command prompt to change the active code page to the one that works
for utf-8 (65001 is apparently Windows' spelling of utf-8) and second change
the font properties of the command prompt (left click upper left corner of
the window, choose Properties, then Font tab) to use Lucida Console, not
Raster Fonts.  If I do those two things then utf-8 data looks correct in my
command prompts.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to