2👍
✅
The result of a
ugettext_lazy()
call can be used wherever you would use a unicode string (an object with typeunicode
) in Python. If you try to use it where a bytestring (astr
object) is expected, things will not work as expected, since augettext_lazy()
object doesn’t know how to convert itself to a bytestring. You can’t use a unicode string inside a bytestring, either, so this is consistent with normal Python behavior.
…
If you ever see output that looks like
"hello <django.utils.functional...>"
, you have tried to insert the result ofugettext_lazy()
into a bytestring. That’s a bug in your code.
Either pass it to unicode()
to get the unicode
from it, or don’t use lazy translation.
Source:stackexchange.com