Django Signals: Automate Reactions to Events

By NSLTD | Published on June 25, 2025

Django

Connect Events to Logic with Django Signals

Signals in Django allow decoupled components to communicate and react to events, such as saving a model or creating a user.

Why Use Signals?

  • Trigger actions automatically when certain events occur
  • Keep your code modular and clean
  • Avoid logic duplication across views or serializers

Basic Example: Welcome Email on User Creation

from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver

@receiver(post_save, sender=User)
def send_welcome_email(sender, instance, created, **kwargs):
    if created:
        print(f"Welcome email sent to {instance.email}")

Common Signals

  • pre_save / post_save
  • pre_delete / post_delete
  • m2m_changed
  • Custom signals for your own app logic

Signals are perfect for background triggers—logging events, sending notifications, updating related models, and more.

“Let the app listen. Let the signal speak.”

Comments

No comments yet. Be the first to comment!

You must be logged in to leave a comment.