django signal

django.contrib.auth.signals.py



from django.dispatch import Signal

user_logged_in = Signal(providing_args=['request', 'user'])









django.contrib.auth.models.py



from django.contrib.auth.signals import user_logged_in

def update_last_login(sender, user, **kwargs):

    """

    A signal receiver which updates the last_login date for

    the user logging in.

    """

    user.last_login = datetime.datetime.now()

    user.save()



user_logged_in.connect(update_last_login)









django.contrib.auth._init_.py

def login(request, user):

    user_logged_in.send(sender=user.__class__, request=request, user=user)

你可能感兴趣的:(django)