Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python gettext错误:Can';t转换为'__代理';对象隐式地访问str_Python_Django_Gettext - Fatal编程技术网

python gettext错误:Can';t转换为'__代理';对象隐式地访问str

python gettext错误:Can';t转换为'__代理';对象隐式地访问str,python,django,gettext,Python,Django,Gettext,我突然发现以前工作的代码中有一个奇怪的错误。我最近从1.9.4升级到了Django 1.9.6 在我的一个观点中,我有: from django.contrib import messages from django.utils.translation import ugettext_lazy as _ messages.success(request, str( _('A string with a ') + '<a target="_blank" href

我突然发现以前工作的代码中有一个奇怪的错误。我最近从1.9.4升级到了Django 1.9.6

在我的一个观点中,我有:

from django.contrib import messages
from django.utils.translation import ugettext_lazy as _

messages.success(request, str( _('A string with a ') +
    '<a target="_blank" href="/preview/' + mymodel.hash + '">' +
    _('link!') + '</a>.'), extra_tags="safehtml"
    )
为什么??我该如何解决这个问题

编辑:
这可以通过在
str()
中包装对
ugettext\u lazy()
的第二次调用来解决(即代码变成
str('link!'))
。这样做可以使视图呈现良好。因此,我现在的问题是:为什么?整个复合字符串已经包装在
str()中了
,正如我所说,这段代码与django的早期版本配合得很好。这是一个bug吗?

\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu>是翻译字符串,其实际翻译结果直到对象在字符串中使用时才确定(即,当您在此处使用
ugettext
时会发生什么情况)

根据给定的:

使用惰性转换作为参数调用str()将在当前区域设置中生成字符串

Can't convert '__proxy__' object to str implicitly