Skip to content
Advertisement

django, “is not JSON serializable” when using ugettext_lazy?

I have this in my views.py

JavaScript

Since I start using this import:

from django.utils.translation import ugettext_lazy as _

at this line:

message = _('This is a test message')

I get this error:

JavaScript

Why? What am I doing wrong?

Advertisement

Answer

You can also create you own JSON encoder that will force __proxy__ to unicode.

From https://docs.djangoproject.com/en/1.8/topics/serialization/

JavaScript

So now your code can look like:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement