【发布时间】:2016-01-04 12:39:32
【问题描述】:
目前正在尝试升级 Django 187 --> 191,但在我的模板文件中遇到了意外的翻译问题。在模板中第一次出现跨标签时,我收到以下错误。在我看来,当没有找到 mo/po 文件或与此字符串匹配时,ugettext 没有正确默认返回(目前没有使用 no/norwegian 的翻译文件,所以应该坚持使用现有名称)。
所有翻译都正常工作了很长时间,所以这是出乎意料的......
有什么想法吗?
NoneType' object has no attribute 'get'
Request Method: GET
Request URL: http://shootnscoreit.com/dashboard/
Django Version: 1.9.1
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'get'
Exception Location: /usr/local/lib/python2.7/gettext.py in ugettext, line 400
...
usr/local/lib/python2.7/gettext.py in ugettext
400. tmsg = self._catalog.get(message, missing)
Local Vars
Variable Value
message u'Armoury'
self <DjangoTranslation lang:no>
missing <object object at 0x7f0e72c00740>
...
File "/home/tss/webapps/shoot_django/lib/python2.7/django/templatetags/i18n.py", line 89, in render
value = render_value_in_context(output, context)
File "/home/tss/webapps/shoot_django/lib/python2.7/django/template/base.py", line 1022, in render_value_in_context
value = force_text(value)
File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/encoding.py", line 78, in force_text
s = six.text_type(s)
File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/functional.py", line 114, in __text_cast
return func(*self.__args, **self.__kw)
File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/__init__.py", line 85, in ugettext
return _trans.ugettext(message)
File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 318, in ugettext
return do_translate(message, 'ugettext')
File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 298, in do_translate
result = getattr(translation_object, translation_function)(eol_message)
File "/usr/local/lib/python2.7/gettext.py", line 400, in ugettext
tmsg = self._catalog.get(message, missing)
AttributeError: 'NoneType' object has no attribute 'get'
【问题讨论】:
-
检查日志并在 i18n 上遇到此问题:2015-12-14 13:53:46,856 - py.warnings - 警告 - /home/tss/webapps/shoot_django/lib/python2.7/django /utils/translation/__init__.py:146: RemovedInDjango19警告:不推荐使用语言代码“zh-cn”。请改用“zh-hans”翻译。 return _trans.activate(语言)
-
能够重新创建这个,似乎是当一个无法识别的语言代码(在这种情况下 no = 挪威通用(也可以是 nn 和 nb - ny norsk 和 norsk bokmal))这发生在 django 191 但不是187……奇怪……
-
最终从 'no' ---> 'nb' 迁移了所有语言 cookie,这只是 Django 默认语言中不存在的语言代码。似乎 Django 1.9.1 在这个问题上比 1.8.7 更敏感
-
我在从 1.9 升级到 1.9.1 后看到这个,唯一相关的提交似乎是 github.com/django/django/commit/…
标签: django django-templates django-i18n