Python Django对象正在显示,而不是转换的字符串
我有一个与python库“Matplotlib”相关的问题。实际上,我正在使用这个库创建折线图和条形图,并使用代码添加X轴和Y轴标题Python Django对象正在显示,而不是转换的字符串,python,django,matplotlib,internationalization,translation,Python,Django,Matplotlib,Internationalization,Translation,我有一个与python库“Matplotlib”相关的问题。实际上,我正在使用这个库创建折线图和条形图,并使用代码添加X轴和Y轴标题 yaxis = "Production" xaxis = "year" plt.ylabel(yaxis, fontsize=20) plt.xlabel(xaxis, fontsize=20)![enter image description here][1] 但同时我也希望使用语言翻译i18n 为此我用了 from django.utils.trans
yaxis = "Production"
xaxis = "year"
plt.ylabel(yaxis, fontsize=20)
plt.xlabel(xaxis, fontsize=20)![enter image description here][1]
但同时我也希望使用语言翻译i18n
为此我用了
from django.utils.translation import ugettext_lazy as _
yaxis = _("Production")
xaxis = _("year")
plt.ylabel(yaxis, fontsize=20)
plt.xlabel(xaxis, fontsize=20)
所以它工作得很好,但在Y轴和X轴的转换项所在的图形中,Django对象正在混合
根据:
在中使用转换函数的惰性版本
django.utils.translation(在
它们的名称)以惰性地转换字符串–当访问该值时
而不是当他们被呼叫时。
这些函数存储对字符串的延迟引用,而不是实际的字符串
翻译。当字符串为
在字符串上下文中使用,例如在模板呈现中
替换以下行:
from django.utils.translation import ugettext_lazy as _
with(将返回unicode字符串):
from django.utils.translation import ugettext as _