Reputation: 49
Python version : 2.7.10 Django version : 1.8 Environment : Virtual environment
Problem: Whenever i tried to run ./manage.py runserver or shell I get this error
"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."
Based on some responses on some related posts, I have also checked my wsgi file and it has the updated way of referencing the wsgi application. Here's how my wsgi file looks:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "instant_reports.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Any help/guidance on resolving this ?
Upvotes: 0
Views: 675
Reputation: 2003
Did you use ugettext()
in your code? Change it to ugettext_lazy().
Quoting Django official documentation:
AppRegistryNotReady: This happens when importing an application configuration or a models module triggers code that depends on the app registry.
For example, ugettext() uses the app registry to look up translation catalogs in applications. To translate at import time, you need ugettext_lazy() instead. (Using ugettext() would be a bug, because the translation would happen at import time, rather than at each request depending on the active language.)
Upvotes: 1
Reputation: 1723
You need to use the lazy translation in your settings.py
and any file (views.py
, models.py
) that might get imported while Django is boostrapped.
Upvotes: 0