简体   繁体   English

无法更新Django内置用户的last_login字段

[英]Unable to Update last_login field of Django in-built user

Built in User model of django contains last_login field. django的内置User模型包含last_login字段。 I am updating last_login when user logouts from the website. 当用户从网站注销时,我正在更新last_login

views.py: views.py:

def logout(request):
    template = loader.get_template('logout.html')
    print("I am Loging out... BYY", request.user.id)
    User.objects.filter(id=request.user.id).update(last_login=timezone.now)
    auth.logout(request)
    return HttpResponse(template.render({}, request))

I am getting Error on User.objects.filter(id=request.user.id).update(last_login=timezone.now) which says expected string or bytes-like object 我在User.objects.filter(id=request.user.id).update(last_login=timezone.now)上收到错误, User.objects.filter(id=request.user.id).update(last_login=timezone.now)错误表示expected string or bytes-like object

您必须调用timezone.now方法。

User.objects.filter(id=request.user.id).update(last_login=timezone.now())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django:'字段列表'中的未知列'last_login' - Django: Unknown column 'last_login' in 'field list' 获取特定用户的last_login时间? (django) - Get last_login time for a certain user? (django) 在 Django 中显示加入日期和 last_login - Display join date and last_login in Django 在 Django Rest 框架中使用 Tokenauthentication 进行身份验证时,last_login 字段未更新 - last_login field is not updated when authenticating using Tokenauthentication in Django Rest Framework 自定义user_logged_in信号之前django更新last_login - Custom user_logged_in signal BEFORE django updates last_login 从Django 1.6(南方)升级到1.8不会修改用户表上的“last_login” - Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table 如何更改自定义Django用户创建的数据库列last_login的名称? - How to change the name of db column last_login created by custom Django user? 每次我尝试将用户添加到数据库时,Django中的date_joined和last_login都会出现错误 - date_joined and last_login required error in Django every time i tried to add a User to the database 将 db_table 添加到 model 添加了 last_login 字段 - Adding db_table to model added a last_login field django-registration(1048,“Column'last_login'不能为null”) - django-registration (1048, “Column 'last_login' cannot be null”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM