检查用户是否第一次登录而不使用django

编程入门 行业动态 更新时间:2024-10-25 09:24:16
检查用户是否第一次登录而不使用django-allauth(Check if the user has logged in for the first time without using django-allauth)

我在这里发现了很多关于相同主题的问题,但它们都有一个共同点,即Django-allauth。 但我的项目使用djoser。 我希望用户只有在第一次登录时才能在其个人资料中添加一些其他信息。 我无法使用比较

user.last_login == user.date_joined

当我登录上次登录日期发生变化时,我希望用户登录以便他们进行更改。

我使用Django 1.7和djoser进行登录和身份验证。

I have found a lot of questions here asking about the same topic but they all have one thing in common, i.e. Django-allauth. But my project uses djoser. I want users to add some additional information to their profile only when they log in for the first time. I can not use the comparison of

user.last_login == user.date_joined

as when I log in the last login date changes, and I want the user to log in so they can make the changes.

I am using Django 1.7 and djoser for the login and authentication purpose.

最满意答案

您可以简单地将新的BooleanField (例如名为is_previously_logged_in )和default=False到您的配置文件模型中,并检查每次登录时它是否仍为False 。 然后,您可以将其设置为True这样您就不会向用户显示两次配置文件信息。

You can simply add a new BooleanField (say, named is_previously_logged_in) with default=False to your profile model and check if it is still False at every login. You can then set it to True so that you don't show the profile information to the user twice.

更多推荐

本文发布于:2023-04-27 16:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   用户   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!