如何区分Django中首次注册和常规登录的用户 [英] How to differentiate the first time registered and regular logged in user in django

查看:146
本文介绍了如何区分Django中首次注册和常规登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django allauth来实现我的所有signin, signup and logout功能,并且工作正常.

I am using django allauth for all my signin, signup and logout functionality and working fine.

现在我有一个功能,

1.第一次注册并登录用户时,我需要将其重定向到成功页面/验证页面(/success/)

1.when a user is registered and logged in for the first time, i need to redirect him to a success page/verification page(/success/)

2.已经注册的用户登录后,应将其重定向到/dashboard/

2.When a user who is already registered is logged in, he should be redirected to /dashboard/

截至目前,我已通过settings.py

LOGIN_REDIRECT_URL = /dashboard/

我还观察到,有一个名为last_login的用户对象字段/属性,我们可以从中使用该字段/属性来查找用户的最后登录信息,这是否会有帮助?

Also i have observed that there is field/attribute called last_login for user object from which we can use to find the last login for the user, whether it will be helpful ?

model.py

from django.contrib.auth.models import User

class Profile(models.Model):
    business_name = models.CharField(max_length = 45, null = False, blank = False)
    user = models.ForeignKey(User, unique = True)
    work_field = models.CharField(max_length = 45, null = False, blank = False)
    image = models.ImageField(upload_to = '/images/', null = True, blank = True, max_length = 250)
    image.allow_tags = True
    url = models.URLField(max_length = 255, null = True, blank = True)

推荐答案

我认为您可以检查 last_login 字段(如果您确定用户存在).

I think you can check your last_login field (if you are sure a user exists).

尝试下一个:

profile.user.last_login == profile.user.date_joined: # this may be True if a user logins for a first time

OR

profile.user.last_login == None:

我不知道该字段的确切值,但是您可以尝试并找到首次注册用户的规则.

I don't know the exactly value for the field but you can experiment and find the rule for first-time registered users.

这篇关于如何区分Django中首次注册和常规登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆