Python helps you build web applications and other applications, which makes it popular among programmers and developers. They use it quite frequently to design projects. It is an easy language as it is written in English, and that’s the reason beginners also understand it. Programming becomes simpler when working on a framework. Python has several frameworks and libraries that are designed for the ease of programmers. Django framework that works as a back-end server side. It is an open-source, free, and high-level web framework, which is used for the quick development of secure and maintained websites. It is a really popular framework that is massively used. When working on it, you may encounter the error “Error: django.core.exceptions.appregistrynotready: apps aren’t loaded yet”.
When you are trying to work on a framework, you need to understand the features, functionality, and on what principles it is working. We help you solve the error in an easier way. Check out how the error warning pops up
How the error occurs
When you try to use a Django program after updating, you get the following error
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.
The program code you may have tried that landed you in the error:
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()
Module code
#!/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)
After executing the program code, you get the error in return. Now that you have seen the error and the program code. Check out the ways to handle the error
How To Handle The Error “Error: django.core.exceptions.appregistrynotready: apps aren’t loaded yet”
Solution 1 – Add the following lines on top of the setting
To resolve the error message, you need to add lines in your settings file on the top
import django
django.setup()
In case this will not work, then you should remove the third-party apps you installed in your app list. Try to remove them one by one. It can fix the issue.
Solution 2 – Import correctly
Sometimes, the error occurs only because you use the wrong approach to import the model. Before you import the model, you need to run the Django.setup mentioned above, after that, you can import the model. Have a look at the proper approach to implement
import django
django.setup()
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings')
It resolves the error.
Solution 3 – The same version on server and local
The error can show up because of the different versions of Django on the server and local. For instance, on the local, you have 1.8.1 and, on the server, you have 1.8.5, which causes the issue. To resolve the error message, you need to delete the env folder and then reinstall using the below command
pip install -r requirements.txt
Conclusion
In this post, we discussed the solution to handle the exception “Error: django.core.exceptions.appregistrynotready: apps aren’t loaded yet”. You can easily implement the solutions to resolve the error.
I hope it helps!