I’ve been working with international websites lately. Got this error on the Django admin pages, but no other pages on the website:
DjangoUnicodeDecodeError: Caught an exception while rendering: ‘ascii’ codec can’t decode byte … in position:6: ordinal not in range (128) ….
Went through the following steps:
Strange, this means the data is in the right encoding, but when it is trying to display on the admin page the encoding is getting lost or coerced in to the wrong thing.
After a cup of coffee, I remembered the admin pages sometimes use the unicode() function if you don’t explicitly tell them what to display. Looked into the model code and gasped in horror:
def __unicode__(self): return str(self.title)+u":"
Flip the str to unicode and admin pages work again.
Gotta add that to the code review list.