gpt4 book ai didi

python - AppRegistryNotReady : Apps aren't loaded yet. Django

转载 作者:太空狗 更新时间:2023-10-30 00:21:35 26 4
gpt4 key购买 nike

我正在尝试在谷歌应用引擎上运行 django 1.9。尝试通过 Google API Explorer 访问 API 时出现以下错误。

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.

我已经添加了

builtins:
- deferred: on
- remote_api: on
- django_wsgi: on

handlers:
- url: .*
script: mysite.wsgi.application

env_variables:
DJANGO_SETTINGS_MODULE: 'mysite.settings'

app.yaml 文件中。

wsgi.py 看起来像

import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

我尝试在 models.py 顶部添加 django.setup() 行,但它显示了不同的错误。

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

这个问题的临时解决方案:

看来我需要先打开主页。这样它就会加载数据库,因为我制作了主页以返回所有数据库表内容。一旦数据库列表显示在主页上,我们就可以调用 Google API Explorer。

有什么方法可以改进这个解决方案吗?

最佳答案

您应该首先在脚本中以这种方式启动 django:

import django
django.setup()

参见 https://docs.djangoproject.com/en/1.9/ref/applications/#django.setup

您还可以查看链接的疑难解答部分,了解解决此特定异常的其他可能性。

通过在 services.py 文件的顶部添加以上两行,为我解决了这个问题..

关于python - AppRegistryNotReady : Apps aren't loaded yet. Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35086550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com