[Chicago] Help with PyCon Talk Proposals
Feihong Hsu
hsu.feihong at yahoo.com
Thu Nov 15 16:35:38 CET 2007
No, Django has had issues with unicode in the past. However, the current SVN release finally gets it right (I hope). Django now fully supports the __unicode__() method. The following is from Django Tutorial 1 (http://www.djangoproject.com/documentation/tutorial01/).
====================================================
If __unicode__() doesnt seem to work
If you add the __unicode__() method to your models and dont see any change in how theyre represented, youre most likely using an old version of Django. (This version of the tutorial is written for the latest development version of Django.) If youre using a Subversion checkout of of Djangos development version (see the installation docs for more information), you shouldnt have any problems.
If you want to stick with an older version of Django, youll want to switch to the Django 0.96 tutorial, because this tutorial covers several features that only exist in the Django development version.
...
Why __unicode__() and not __str__()?
If youre familiar with Python, you might be in the habit of adding __str__() methods to your classes, not __unicode__() methods. We use __unicode__() here because Django models deal with Unicode by default. All data stored in your database is converted to Unicode when its returned.
Django models have a default __str__() method that calls __unicode__() and converts the result to a UTF-8 bytestring. This means that unicode(p) will return a Unicode string, and str(p) will return a normal string, with characters encoded as UTF-8.
If all of this is jibberish to you, just remember to add __unicode__() methods to your models. With any luck, things should Just Work for you.
====================================================
It's a shame that it didn't Just Work before, but remember that Django came out of Lawrence, Kansas, where people typically aren't concerned with representing foreign characters.
- Feihong
Carl Karsten <carl at personnelware.com> wrote: Feihong Hsu wrote:
> I'm not really familiar with Unicode issues involving email. Were you able to resolve the problem in the end?
I was told "make sure the subject are ascii to reduce being labeled as spam."
this took care of it:
subject = safe_ascii_encode(subject)
>
> But I personally haven't had any database or GUI framework issues with Unicode in a long time. Well, MySQL comes to mind, but they supposedly fixed those problems.
I think there was something in the djagno unit tests that bit me. like I hadn't
created the db right.
I often wonder "why doesn't this stuff just work?" and conclude that I must not
understand it.
Carl K
_______________________________________________
Chicago mailing list
Chicago at python.org
http://mail.python.org/mailman/listinfo/chicago
---------------------------------
Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/chicago/attachments/20071115/4501d707/attachment.htm
More information about the Chicago
mailing list