BeginnerCoder

Lesson 21 — Signals

Run code when something happens

A signal lets one part of the app say "a post was saved" and other parts react — send an email, clear a cache — without the save code knowing about them. In Django: @receiver(post_save, sender=Post).

The idea is a list of listeners (functions). Sending the signal calls each one:

for listener in listeners:
    listener(obj)

Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.

Why it matters: side effects stay separate, so adding a new reaction never breaks saving.

Want it another way?
Task

Register a second listener that prints "email sent for <id>", then save object 7.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Django Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.