gpt4 book ai didi

python - 如何修复 "plural forms could be dangerous"django 错误?

转载 作者:太空狗 更新时间:2023-10-29 18:28:37 26 4
gpt4 key购买 nike

我不明白。如果我将 Accept-Language header 设置为除“en”(de、pl、es)以外的任何内容,甚至是不存在的内容(如 xxs),应用程序都不会吐出这个错误,但是当我将它设置为“en”时它会发生。它只发生在 Windows 上(最新的 gettext 工具)。这是堆栈跟踪:

Traceback (most recent call last):
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han
dlers\exception.py", line 39, in inner
response = get_response(request)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han
dlers\base.py", line 244, in _legacy_get_response
response = middleware_method(request)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\middlewa
re\locale.py", line 29, in process_request
translation.activate(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\__init__.py", line 161, in activate
return _trans.activate(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 238, in activate
_active.value = translation(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 227, in translation
_translations[language] = DjangoTranslation(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 129, in __init__
self._add_installed_apps_translations()
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 176, in _add_installed_apps_translations
translation = self._new_gnu_trans(localedir)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 156, in _new_gnu_trans
fallback=use_null_fallback)
File "C:\Python35\lib\gettext.py", line 426, in translation
t = _translations.setdefault(key, class_(fp))
File "C:\Python35\lib\gettext.py", line 162, in __init__
self._parse(fp)
File "C:\Python35\lib\gettext.py", line 297, in _parse
self.plural = c2py(plural)
File "C:\Python35\lib\gettext.py", line 76, in c2py
raise ValueError('plural forms expression could be dangerous')
ValueError: plural forms expression could be dangerous

我在我的 django.po 文件中正确设置了 plural-forms:

"Plural-Forms: nplurals=2; plural=(n != 1);\n"

为什么会发生这种情况以及如何解决?

最佳答案

我找到了答案 - 该错误的原因是我的无能 :)。我在项目的根目录中运行了 django-admin makemessages 命令,所以在 _env 和里面的所有包旁边。此命令使用默认的 django.po 文件模板为几个项目创建了语言文件,因此它们包含诸如 plural-forms=INTEGER 之类的内容和其他内容,这导致了上述错误。

关于python - 如何修复 "plural forms could be dangerous"django 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41924444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com