从不同的 Django 应用程序委托

Delegate from different Django app

假设我有两个 Django 应用程序,abcxyzabc 应用程序是一个应使用 pip3 安装的程序包,xyz 是一些使用 abc.

中的功能的自定义应用程序

xyz 如何提供在 abc 的视图中使用的委托方法?假设 abc 需要发送消息,它不关心是通过短信、电子邮件还是鸟类载体发送,所以如果 xyz 可以提供委托方法,可以从 abc,没有 abc 关心实现。

Python 可以顺利处理委托,但如何在 Django 视图中连接它?

我知道我可以使用消息队列或回调 url,但我觉得有点奇怪,因为没有更简单的方法来做到这一点。

Signals 可以帮助您实现您的目标。

来自 Django 关于该主题的文档:

Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.

以下是有关该主题的一些其他资源: