From 350d15d79c01d2dd7c6c3196a4a01a5f63b45148 Mon Sep 17 00:00:00 2001 From: Roxane Date: Sat, 2 Oct 2021 15:46:04 +0200 Subject: [PATCH] [4.0.x] Fixed #33163 -- Added example of connection signal handlers in AppConfig.ready() to docs. Backport of 2d124f6a1c45afdde8be90c01043e0b14455d41e from main --- AUTHORS | 1 + docs/topics/signals.txt | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 146b0be3a3..00e51d6bc8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -816,6 +816,7 @@ answer newbie questions, and generally made Django that much better: Romain Garrigues Ronny Haryanto Ross Poulton + Roxane Bellot Rozza Rudolph Froger Rudy Mutter diff --git a/docs/topics/signals.txt b/docs/topics/signals.txt index f4c6290a14..3e5c09b63a 100644 --- a/docs/topics/signals.txt +++ b/docs/topics/signals.txt @@ -136,9 +136,21 @@ Now, our ``my_callback`` function will be called each time a request finishes. In practice, signal handlers are usually defined in a ``signals`` submodule of the application they relate to. Signal receivers are connected in the :meth:`~django.apps.AppConfig.ready` method of your - application configuration class. If you're using the :func:`receiver` - decorator, import the ``signals`` submodule inside - :meth:`~django.apps.AppConfig.ready`. + application :ref:`configuration class `. If + you're using the :func:`receiver` decorator, import the ``signals`` + submodule inside :meth:`~django.apps.AppConfig.ready`, this will implicitly + connect signal handlers:: + + from django.apps import AppConfig + + class MyAppConfig(AppConfig): + ... + + def ready(self): + # Implicitly connect a signal handlers decorated with @receiver. + from . import signals + # Explicitly connect a signal handler. + signals.request_finished.connect(signals.my_callback) .. note::