可以使用信号亮signal,使用方法如下:
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
@receiver(user_logged_in)
def record_login_info(sender, request, user, **kwargs):
pass
这样record_login_info函数就会在用户登录成功之后被调用