neu*_*rix 1 python django unicode typeerror
我正在将GeoDjango示例与类一起使用WorldBorder。我的问题是我无法打印出所选国家的名称。当我尝试执行
from django.utils.translation import ugettext_lazy as _
...
location = fromstr(... , srid=4326)
country = WorldBorder.objects.get(mpoly__intersects=location)
print _('User country determined to %s') %country.name
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
Python: TypeError: 'unicode' object is not callable
Run Code Online (Sandbox Code Playgroud)
当我删除 时ugettext_lazy,一切正常。如何保留翻译选项并使字符串正常工作?
看起来您正在使用 Python shell。在那里, _ 将取最后一个表达式的值。所以 _ 最终成为第三行之后的 WorldBorder 实例。为避免此问题,当您在 shell 中使用 translate 时,请将 ugettext_lazy 别名为“_”以外的其他名称。
| 归档时间: |
|
| 查看次数: |
1164 次 |
| 最近记录: |