python runtime_error ai_generated true

django.core.exceptions.ImproperlyConfigured: Receiver must be a callable or a tuple of callables.

ID: python/django-signal-receiver-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-04-29First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

信号连接时传递了非函数对象

generic

中文

在connect()方法中传入的不是函数或可调用对象

Workarounds

  1. 95% success
    from django.db.models.signals import post_save; post_save.connect(my_handler)
  2. 90% success
    from django.dispatch import receiver; @receiver(post_save, sender=MyModel)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Django不支持字符串引用,必须是实际函数

  2. 80% fail

    信号不会触发,功能缺失