I have a flash message in Django that is built using a standard char field from a memberships model.
messages.add_message(request,
messages.INFO,
'{0} membership created'.format(membership.name))
This works just fine unless memberships.name contains unicode characters in which case I get a UnicodeEncodeError. I can fix this by prepending the string with u to create a unicode string but I don’t understand why this is necessary as the docs state that Django assumes all bytestrings are in UTF-8. Should I be going through my app and changing all strings to unicode strings?
This isn’t really an issue with Django. It looks like you’re being caught out by a bug in the way
str.formathandles unicode arguments, Python Issue 7300One workaround is to use a unicode string, another is to use
%formatting.