Thursday, March 19, 2009

Another strange django unicode error solved!

Today while trying to my final product to one of our customer's an ugly little error shot back at me when I tried editting any of the imported records into the database. "django ascii codec can't encode ..." bla bla it would complain and refuses to render the said template. Tracking down the problem down, I found it to the __str__ method being returned one of my models.

After changing the database encoding for my MySQL database ( sucky on windoze ), it still stubbornly spat back the same error at me. Finally after searching around more I found the smart_str method's usage here.

Kudos! It works now. So instead of returning the normal 'str(' I do a 'smart_str(' and everything is back to it's hunky doriness!