python - 尝试安装 django-seo 时出现 AppRegistryNotReady 错误
问题描述
我跑了pip install djangoseo
,然后用 pip freeze 确认了
添加rollyourown.seo
到我的INSTALLED_APPS
设置
添加"django.core.context_processors.request"
到TEMPLATE_CONTEXT_PROCESSORS
设置
当我尝试运行 pythonmanage.py syncdb
或运行我的应用程序时,出现以下错误
AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
解决方案
当您尝试在 django 加载模型之前访问模型时,会引发 AppRegistryNotReady("Apps are not loaded yet.") 。在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")
推荐阅读
- mysql - 无法创建/写入文件'/path/file.csv'(错误代码:13“权限被拒绝”)
- regex - 正则表达式只允许某些字符
- sql - 从字符串中删除特殊字符 +
- ruby-on-rails - 审核 gem 以在管理面板中列出跟踪的更改
- python - Python 性能时间减去
- python - 在 Python 中使用字典时,如何返回具有相同值的键?
- c - gcc 错误 - 可能是库
- facebook - 带有移动应用程序和后端 Web 服务器的 Facebook OAuth
- javascript - 如何在 Liferay 中将“destoryOnHide”或“destroyOnClose”设置为现有的模态对话框?
- sql - 如何加入两个表的行数不同?