Django users, In my Django app, I want to allow users to enter Unicode strings. But if they do, I get UnicodeEncodeError when I call format() to embed their string into other strings. Is there an easy way to tolerate the Unicode? Details: After prompting the user for name, I may have a line of code like: log('Name entered was: {0}'.format(name)) With Python 2.7.3 and Django 1.4.3, this raises exception UnicodeEncodeError if the user entered a string containing Unicode chars, because it tries to embed Unicode chars into my ASCII string template. So, I have to I change it to: log(u'Name entered was: {0}'.format(name)) I have many thousands of such lines in my 200,000+ lines of Python and Django code. Is there a master switch somewhere that would cause a Python 2.x string literal to default to Unicode instead of ASCII, as it does in Python 3? Or do I have to explicitly change '' to u'' in all such places? I looked into adding a line like this to the top of the file, but no luck because it seems to only affect the encoding of Unicode string literals (u''), not regular string literals (''): # -*- coding: utf-8 -*- Any suggestions? Much appreciated. Thanks! --Fred Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/ Bristle Software, Inc -- http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/57101921.80505%40bristle.com. For more options, visit https://groups.google.com/d/optout. |
- Any way to tolerate Unicode w/o changing '' to u''?... Fred Stluka
- Re: Any way to tolerate Unicode w/o changing '' to ... Stephen J. Butler
- Re: Any way to tolerate Unicode w/o changing '' to ... Tim Graham