Django 无法在应用程序启动之前初始化翻译基础结构
我正在跟踪,但当我按照它所说的做时,我会收到以下错误消息Django 无法在应用程序启动之前初始化翻译基础结构,django,Django,我正在跟踪,但当我按照它所说的做时,我会收到以下错误消息 "The translation infrastructure cannot be initialized before the " django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't m
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
设置.py
我理解这是因为在加载必要的lib之前调用了translation,但是如果文档中这样说,我如何更改它呢
WSGI.py
您需要使用@Sayse Wow的
ugettext\u lazy
可能的副本。我认为,如果使用了错误的方法,将对性能产生巨大影响。谢谢你的提醒。你能接电话吗?成功了。我将标记为解决方案。我打赌它将来会帮助人们。:)电动汽车。谢谢,但通常情况下,如果你认为这些问题是另一篇文章的翻版(我在这里做了一部分),那么你就不愿意回答这些问题,因为这实际上会让未来的读者更难找到正确的答案。很高兴它能帮上忙!
LANGUAGE_CODE = 'en'
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale/'),
)
USE_I18N = True
USE_L10N = True
USE_TZ = True
TIME_ZONE = 'Europe/Copenhagen'
from django.utils.translation import ugettext as _
LANGUAGES = [
('da', _('Danish')),
('en', _('English')),
]
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app.settings")
application = get_wsgi_application()