Ich versuche Signale zu lernen. In der apps.py unten gibt es ein paar kommentierte Zeilen. Sobald ich aus .models EmpfängerModel, SenderModel auskommentiere, bekomme ich django.core.exceptions.AppRegistryNotReady: Apps sind noch nicht geladen.Apps sind noch nicht geladen (beim Lernen von Signalen)
Können Sie mir helfen zu verstehen, was ich falsch mache?
demo_signals/my_app/models.py
from django.db import models
from django.dispatch import receiver
from django.db.models.signals import post_save
class SenderModel(models.Model):
pass
class ReceiverModel(models.Model):
pass
@receiver(post_save, sender=SenderModel)
def my_callback(self, sender, **kwargs):
print("Saving finished!")
demo_signals/demo_signals/settings.py
INSTALLED_APPS = [
...
'my_app.apps.MyAppConfig',
]
demo_signals/my_app/apps.py
from django.apps import AppConfig
from django.db.models.signals import Signal
#from .models import ReceiverModel, SenderModel
class MyAppConfig(AppConfig):
name = 'my_app'
def ready(self):
print("Here")
#Signal.connect(self, ReceiverModel, SenderModel)
Ein Teil der Zurückverfolgungs
File "/home/michael/workspace/demo_signals/my_app/apps.py", line 3, in <module>
from .models import ReceiverModel, SenderModel
File "/home/michael/workspace/demo_signals/my_app/models.py", line 5, in <module>
class SenderModel(models.Model):
File "/home/michael/workspace/PhotoArchive/venv/lib/python3.5/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/michael/workspace/PhotoArchive/venv/lib/python3.5/site-packages/django/apps/registry.py", line 240, in get_containing_app_config
self.check_apps_ready()
File "/home/michael/workspace/PhotoArchive/venv/lib/python3.5/site-packages/django/apps/registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
Thank you very much. – Michael