我尝试使用ugettext_lazy和此代码进行响应。
return Response({"detail": _("New password has been saved.")})
我期望的响应值为{"detail": "New password has been saved."
但实际返回值为
{
"detail": [
"N",
"e",
"w",
" ",
"p",
"a",
"s",
"s",
"w",
"o",
"r",
"d",
" ",
"h",
"a",
"s",
" ",
"b",
"e",
"e",
"n",
" ",
"s",
"a",
"v",
"e",
"d",
"."
]
}
为什么所有字符都返回分隔值并包装在列表中?
答案 0 :(得分:0)
尝试一下;
from django.utils.encoding import force_text
return Response({"detail": force_text(_("New password has been saved."))})