Using Signals in Django

Nuno Bispo
Django Unleashed
Published in
3 min readOct 10, 2023

--

The Signal framework allows certain senders to notify a set of receivers when some action has taken place.

Image by Author

Django, a high-level Python web framework, is known for its “batteries-included” philosophy, offering developers a wide array of tools and utilities right out of the box.

One such utility is the signals framework, which allows certain senders to notify a set of receivers when some action has taken place.

In essence, signals are Django’s implementation of the observer pattern.

What are Signals?

Signals allow decoupled applications to get notified when certain actions occur elsewhere in the application.

They’re especially useful when you need to associate events that aren’t tightly coupled in your codebase.

For example, you might want to notify a user every time a new comment is added to a post they authored, even if the comment and user models are in different apps.

How Do Signals Work?

At a high level, the process is as follows:

Define a Signal: This is a new instance of the Signal class.

Connect a Receiver: This is a function or an instance method that gets linked to a signal. It gets called when the signal is sent.

--

--

Nuno Bispo
Django Unleashed

➡️ Content Creator 📜 ➡️ Software Builder 🧑‍💻 ➡️ Follow me for content about 🐍 Python 📘 Django 🧠 A.I.