为什么rest_auth中的ugettext_lazy返回一个奇怪的值?

时间:2019-10-09 14:55:36

标签: django

我尝试使用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",
        "."
    ]
}

为什么所有字符都返回分隔值并包装在列表中?

1 个答案:

答案 0 :(得分:0)

尝试一下;

from django.utils.encoding import force_text

return Response({"detail": force_text(_("New password has been saved."))})