【问题标题】:AttributeError at /notify/ 'User' object has no attribute 'get'/notify/ 'User' 对象的 AttributeError 没有属性 'get'
【发布时间】:2020-11-01 09:24:08
【问题描述】:

在 views.py 中创建用户对象时。它告诉我和错误 AttributeError at /notify/ 'User' object has no attribute 'get' 我该如何解决它。

from django.contrib.auth.models import User

class NotifyView(TemplateView):
    template_name ='notify/home.html'

    def get(self,request,*args, **kwargs):
        print('oye',request.user)
        user = User.objects.get(username=request.user)
        user.notifications.mark_all_as_read(user) 
        return user

如果需要更多信息而不是在评论会话中告诉我,我将使用该信息更新我的问题。谢谢!

【问题讨论】:

    标签: python django django-models django-views django-templates


    【解决方案1】:

    将函数名称更改为“get_user”或“get_object”之类的名称。

    【讨论】:

    猜你喜欢
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 2014-09-08
    • 2021-02-24
    • 2018-05-09
    相关资源
    最近更新 更多