On the tutorial page for the Django web framework, the author explains why adding a __unicode__()
method is preferred than a __str__()
with the following reason:
Django models have a default
__str__()
method that calls__unicode__()
and converts the result to a UTF-8 bytestring. This means thatunicode(p)
will return a Unicode string, andstr(p)
will return a normal string, with characters encoded as UTF-8.
I don't understand what's the difference between a Unicode string and a string with characters encoded as UTF-8. I thought UTF-8 is one of the encodings for Unicode?