- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
添加时出现异常:
导入信号
在init.py 文件(apps/application/init.py)
从模型导入审核
在 signals.py 文件中 (apps/application/signals.py)
当模型 Review 中有插入时,我想发送一个 http 请求。
所以我需要导入Review模型(在__init.py__
文件中)来执行下面的代码:
@receiver (pre_save, sender = Review)
def my_handler (sender, ** kwargs):
....
最佳答案
在 Django 的 source 中,这是异常的来源:
def check_apps_ready(self):
"""Raise an exception if all apps haven't been imported yet."""
if not self.apps_ready:
raise AppRegistryNotReady("Apps aren't loaded yet.")
如您所见,请确保每个应用程序都就绪(已加载)。一般来说,当它与信号相关时,通常有两种情况。
循环导入
确保您的项目中没有。这可能会导致错误。
在应用加载前注册信号
参见 this了解更多信息。但是,帮助我理解 Django 在幕后如何工作的一件事是以下声明:
It is important to understand that a Django application is just a set of code that interacts with various parts of the framework. There’s no such thing as an Application object. However, there’s a few places where Django needs to interact with installed applications, mainly for configuration and also for introspection. That’s why the application registry maintains metadata in an AppConfig instance for each installed application.
因此,您可以做的是覆盖名为 AppConfig.ready()
的 AppConfig
方法之一。它允许您执行初始化任务,例如注册信号。
# yourApp/__init__.py
default_app_config = 'yourappname.apps.YourAppConfig'
# yourApp/apps.py
from django.apps import AppConfig
class YourAppConfig(AppConfig):
name = 'yourappname'
def ready(self):
from yourappname import signals
更多信息
为了便于解释,这是从 Django 1.7+ 开始推荐的做法,这很可能是您的情况。其背后的逻辑是 application registry保留一个 bool 值 ready
,仅在注册表完全填充并且所有 AppConfig.ready()
方法都被设置为 True
叫了。
关于python - django.core.exceptions.AppRegistryNotReady : Apps aren't loaded yet. 文件初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51081783/
自从我处理 django 以来已经有一段时间了,我正在处理一些可能有点旧的代码,现在是 Django 1.7。这个堆栈跟踪是关于什么的? 它不是通过 runserver 发生的,而是通过使用应用程序模
出于某种原因,我的表格行间距不正确,只是将新行覆盖在旧行上。我得到的不是 2 行表,而是 1 行表,其中 2 行相互重叠。这是我的代码的相关部分:
我正在尝试使用自定义用户安装 django-registration-redux。 我已将此包含在我的 settings.py 中: AUTH_USER_MODEL = 'app.customUser
我已在 azure 门户中设置了 Azure Frontdoor。我已经创建了 2个前端主机 myappdev1.azurefd.net dev1.myapp.com 后端池具有以下内容 1.Back
我已在 azure 门户中设置了 Azure Frontdoor。我已经创建了 2个前端主机 myappdev1.azurefd.net dev1.myapp.com 后端池具有以下内容 1.Back
使用来自 Django tutorial 的(部分)投票应用程序例如,我正在尝试获取 pytest-django运行。 使用命令 django-admin startproject mysite2 ,
因此,我尝试向 Django 1.10 应用程序添加一些代码,这些代码仅在服务器启动时运行。我从 here 获取了有关如何执行此操作的说明。和 here 。每次我尝试运行 python 控制台时,我都
我在 IntelliJ IDEA 中使用 Kotlin 插件时遇到问题。首先,打开一个kotlin项目,弹出我需要在这个项目中配置kotlin。但是当我从“工具”菜单中这样做时,它会显示“没有可用的配
请注意,我已经查看了这些线程,但它们没有解决我的问题: (过时的信息,请参阅下面的文档)Access Snowflake query results through PowerBI (我希望这能解决我
当 7 个可用列中的任何 3 个包含该行的数据时,我需要包含行。有没有做类似事情的最佳实践?我想出的解决方案似乎很好,只是想知道是否有更可接受的模式?见 here了解详细信息。以下是我要完成的工作的要
babel-preset-es2015已安装,并且可以使用 es6 功能,如下面 let a = 2; . 但无法使用 es6 模块功能 import fs from 'fs'如下: $ babel-
当我尝试将 View 导入 django 应用程序的 apps.py 模块时出现此错误。我正在使用 django 2.2.9、python 3.7.6、django-oscar 2.0.4。我已覆盖结
我正在使用此代码来填充我的数据库: import os def populate(): python_cat = add_cat('Python') add_page(cat=pyth
我已经将我的 django webapp 部署到我的 heroku 服务器并且它工作正常,直到我添加了一个 websocket 连接,该连接在创建模型对象后立即在单独的 url 中显示该模型对象的内容
尝试阅读文档并纠正一些与 sass 相关的问题。向组件添加了“lang=scss”,但不确定如何解决此问题。任何指导都会有所帮助。 rollup v2.19.0 bundles src/main.js
我使用 django 1.10.5 和 celery 4.0.2。我有这样的结构。 -proj -application __init__.py celery.py cel
所以我正在学习这个 javascript 游戏制作教程,但我真的找不到我做了什么才能使我的红色方 block 不显示在屏幕上。事实上,我确实认为这是速度问题,因为当我在控制台中更改对象的速度时,它出现
从 1.8 升级到 django 1.9 时出现此错误。我检查了类似问题的答案,但我认为这不是任何第三方软件包或应用程序的问题。 Traceback (most recent call last):
我从 Django 1.8 升级到 1.9 但遇到了这个问题 django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. s
我有一个功能性 Django 应用程序,在我看来它有许多 Google Text-To-Speech API 调用和数据库读/写。在本地测试时,加载页面大约需要 3 秒,但是当我将应用程序实时部署到
我是一名优秀的程序员,十分优秀!