AppRegistryNotReady: Apps aren't loaded yet. Django
You should first initiate django this way in your script:
import django
django.setup()
See https://docs.djangoproject.com/en/1.9/ref/applications/#django.setup
You can also look at the Troubleshooting section of the link to see other possibilities to solve this aprticular exception.
By adding the above two lines at the top of services.py
file solves this problem for me..
Avinash Raj
Everybody stand back, I know regular expressions! Top 50 users from India. Top users from Chennai. Github Profile
Updated on June 08, 2022Comments
-
Avinash Raj almost 2 years
I'm trying to run django 1.9 on google app engine. Got the below error when trying to access API's through Google API Explorer.
Traceback (most recent call last): File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject __import__(cumulative_path) File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module> from cityguide.api.internal.categories import Categories File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module> from cityguide.models import Category File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 8, in <module> class ContactDetails(models.Model): File "/home/gemini/projects/cityguide-backend/src/lib/django/db/models/base.py", line 94, in __new__ app_config = apps.get_containing_app_config(module) File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 239, in get_containing_app_config self.check_apps_ready() File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 124, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") AppRegistryNotReady: Apps aren't loaded yet.
I already added
builtins: - deferred: on - remote_api: on - django_wsgi: on handlers: - url: .* script: mysite.wsgi.application env_variables: DJANGO_SETTINGS_MODULE: 'mysite.settings'
inside
app.yaml
file.wsgi.py
looks likeimport os from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") application = get_wsgi_application()
I tried adding
django.setup()
line on the top ofmodels.py
but it shows a different error.ERROR 2016-02-01 10:03:02,918 wsgi.py:263] Traceback (most recent call last): File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject __import__(cumulative_path) File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module> from cityguide.api.internal.categories import Categories File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module> from cityguide.models import Category File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 6, in <module> django.setup() File "/home/gemini/projects/cityguide-backend/src/lib/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 115, in populate app_config.ready() File "/home/gemini/projects/cityguide-backend/src/lib/django/contrib/admin/apps.py", line 22, in ready self.module.autodiscover() File "/home/gemini/projects/cityguide-backend/src/lib/django/contrib/admin/__init__.py", line 26, in autodiscover autodiscover_modules('admin', register_to=site) File "/home/gemini/projects/cityguide-backend/src/lib/django/utils/module_loading.py", line 50, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/home/gemini/projects/cityguide-backend/src/cityguide/admin.py", line 2, in <module> from cityguide.models import Category ImportError: cannot import name Category ERROR 2016-02-01 10:03:02,919 wsgi.py:263] Traceback (most recent call last): File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject __import__(cumulative_path) File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module> from cityguide.api.internal.categories import Categories File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module> INFO 2016-02-01 10:03:03,000 module.py:794] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 - from cityguide.models import Category INFO 2016-02-01 10:03:03,001 module.py:794] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 - File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 6, in <module> INFO 2016-02-01 10:03:03,001 module.py:794] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 60 django.setup() INFO 2016-02-01 10:03:03,001 module.py:794] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 60 File "/home/gemini/projects/cityguide-backend/src/lib/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 78, in populate raise RuntimeError("populate() isn't reentrant") RuntimeError: populate() isn't reentrant
Temporary solution for this problem:
Seems like I need to open the home page first. So that it would loads the db since I made the homepage to return all the db table contents . Once the db lists shown on the home page, we are ready to call the Google API Explorer.
Is there any way to refine this solution?
-
Håken Lid over 8 yearsThe error message usually means that
application = get_wsgi_application()
has not run. For instance if you import django models directly. I think there's some setup process needed to connect the python models to the database. -
Håken Lid over 8 yearsI'm not sure what happens in this step
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject __import__(cumulative_path)
, but it must be a different wsgi.py from the one in the django project. Maybeget_wsgi_application()
step hasn't run. -
Louis over 8 years@AvinashRaj Does it work if you try running your site with Django's
manage.py runserver
? -
Avinash Raj over 8 years@Louis no, it won't..
-
-
Håken Lid over 8 yearsIt might have to be added to this file.
/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py
-
Avinash Raj over 8 years@HåkenLid pls see my update.. I have added a temp solution.
-
Håken Lid over 8 years@AvinashRaj I can't suggest a better permanent solution. I've never used django with google app engine or the Google API explorer.