. Advertisement .
..3..
. Advertisement .
..4..
How to solve the problem – django.core.exceptions.appregistrynotready: apps aren’t loaded yet.? I have the sample detail:
import os
import sys
path = '/Users/Peterhon/Desktop/dict/'
if path not in sys.path:
sys.path.append(path)
os.chdir(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")
import django
django.setup()
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.arg)
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
While I was running it, I found the warning message:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 177, in fetch_command
commands = get_commands()
File "/usr/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 72, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
That is my question in my midterm exam, and it is urgent. I searched the solutions on some websites, but I didn’t get it. I may miss any line or other changes. I appreciate your assistance!
The cause: Your
wsgi.py
will be used by./manage.py runserver
, but it appears that the stack trace you provided at the beginning does not include the wsgi file. As a result, the error occurs before the wsgi file has been loaded.I’m wondering whether there’s something wrong with your setup because you appear to be using the new style wsgi and you note that “the django version on the server is 1.8.5, and the local is 1.8.1”.
The solution: The following are the steps I recommend:
pip install -r requirements.txt
or something similar.This is what I encountered today. There was an app missing from INSTALLED_APPS. It was removed and the exception was resolved. Apps that aren’t allowed to be imported will also trigger an AppRegistryNotReady exception.
This issue can also be caused by trying to import an app-level file into a project-level file. Celery Beat is an example of a project I am currently working on. I tried to define task schedules at app level using dictionaries. These were then imported into the celery.py file. Django threw an AppRegistryNotReady exception when I imported the dictionary from the app to the project. The exception can also be caused by importing items from other apps.