尝试安装 django-seo 时出现 AppRegistryNotReady 错误



我运行了pip install djangoseo,然后用点冻结确认了它

为我的INSTALLED_APPS设置添加了rollyourown.seo

TEMPLATE_CONTEXT_PROCESSORS设置添加了"django.core.context_processors.request"

当我尝试运行pythonmanage.py syncdb或运行我的应用程序时,出现以下错误

AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

当你尝试在 django 加载模型之前访问模型时,会引发 AppRegistryNotReady("Apps are not loaded."(。apps.py 文件中,覆盖ready方法,该方法是一个触发器,表明django已经完成了它的一部分,并且模型的导入或任何与模型相关的东西都应该在那里。

functions.py
def whatever():
from . import models

__init__.py
from .functions import whatever

"whatever"函数可能在内部导入模型。因此,在应用程序开始时,您尝试导入任何导入模型的内容,而 django 尚未完成加载它,因此例外。

溶液:

__init__.py
default_app_config = 'users.apps.UserConfig'

apps.py
class UserConfig(AppConfig):
name = 'users'
def ready(self):
try:
from .functions import whatever
except Exception as e:
print("DON'T WORRY")

相关内容

  • 没有找到相关文章

最新更新