On Mon, 2009-02-16 at 17:55 -0800, Polat Tuzla wrote: > Hi, > I've the same django app deployed to my local mac os x and linux > server. I print the username in my view function to the standart > output: > def my_view(request): > print request.user > > On mac it prints: > İşÖ > > which is what i expect. But on linux it prints: > \xc4\xb0\xc5\x9f\xc3\x96
I'm not quite sure why the Linux system doesn't display characters, although the data is correct. However, it's almost certainly terminal related: at some point Python has to format the result in a fashion that can be displayed on the terminal ("in the terminal application" would be a bit more appropriate to today's implementations, I guess) and your Linux and Mac systems don't necessarily coincide in their capabilities. Most Linux setups will be fine, but there are reasons why it might be restricted to something like, say, only ASCII (accessing via telnet or ssh with restricted negotiation, for example). You are asking Python to use the __str__ method on the model. Unless you somehow tell it that the result should be a unicode object, it will assume a str. Django uses the User.__unicode__ method and UTF-8 encodes it. The Linux output you're seeing is consistent with this: it's the UTF-8 encoding of the original string. > > > If I change my view code as: > def my_view(request): > print u"%s" % request.user > > On mac it prints the same as before: > İşÖ > > But on linux it raises a UnicodeEncodeError: > UnicodeEncodeError: 'ascii' codec can't encode characters in > position 0-2: ordinal not in range(128) This would be consistent with your terminal not supporting something like UTF_8 output -- or, rather, with Python thinking that the output has to be displayed in ASCII. Don't get too hung up on the results of print output (I realise it might hamper some debugging approaches, but it's the debugging approach that is causing the problem here, not some bigger issue). There's a big variable involved -- terminal encoding type -- that isn't present in normal code execution. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---