O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

25.3.1 Informing the User of Login/Logout Actions

To begin, we can create a new file under user/signals.py.

Our first goal is to import our necessary tools. We need the actual signals from auth as well as the success() function from the messages app. We then import the @receiver() decorator, which allows us to register our function to be called when a specific signal is sent, as shown in Example 25.4.

Example 25.4: Project Code

user/signals.py in 4bd73cbe74

1   from django.contrib.auth.signals import ( 2       user_logged_in, user_logged_out) 3   from django.contrib.messages import success 4   from django.dispatch import receiver

In Example 25.5, we first program display_login_message(), a function that displays ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required