Django: signal when user logs in?

In addition to @PhoebeB answer: you can also use @receiver decorator like this:

from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver

@receiver(user_logged_in)
def post_login(sender, user, request, **kwargs):
    ...do your stuff..

And if you put it into signals.py in your app dir, then add this to apps.py:

class AppNameConfig(AppConfig):
    ...
    def ready(self):
        import app_name.signals

You can use a signal like this (I put mine in models.py)

from django.contrib.auth.signals import user_logged_in


def do_stuff(sender, user, request, **kwargs):
    whatever...

user_logged_in.connect(do_stuff)

See django docs: https://docs.djangoproject.com/en/dev/ref/contrib/auth/#module-django.contrib.auth.signals and here http://docs.djangoproject.com/en/dev/topics/signals/