类型对象“通知”没有属性“对象”

奥斯曼·哈马肖尔(Osman Hamashool)

我从views.py中收到此错误:

类型对象“通知”没有属性“对象”

和我的views.py:

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from notification.models import Notification

def show_notification(request, notification_id):
    n = Notification.object.get(id=notification_id)

    return render_to_response('notification.html', {'notification':n})
def delete_notification(request, notification_id):
    n = Notification.object.get(id=notification_id)
    n.viewed = True
    n.save()

还有我的models.py:

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver


class Notification(models.Model):
    title = models.CharField(max_length=250)
    message = models.TextField()
    viewed = models.BooleanField(default=False)
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)


def create_welcome_message(sender, **kwargs):
    if kwargs['created']:
        noti=Notification.objects.create(user=kwargs['instance'],
                                    title="Welcome Message",
                                    message="Thank you for singing up!")


post_save.connect(create_welcome_message, sender=User)

我已经想了很久了。使用这种语言。然后帮我解决这个错误。

德邦帕迪亚

您正在尝试使用来获取通知Notification.object.get(id=notification.id)

替换objectobjects以查询通知。

例如 Notification.objects.get(id=notification.id)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型对象“ UserProfile”没有属性“对象”

“用户”对象没有“通知”属性

类型对象'ModelDeclarativeMetaclass'没有属性'Meta'

AttributeError:类型对象没有属性

类型对象x没有属性y

错误:类型对象没有属性“查询”

类型对象 'HttpResponse' 没有属性 'User'

类型联合对象或对象数组上没有属性

属性错误:类型对象“点”没有属性“方向”

属性错误:类型对象“全局”没有属性“光标”

Python属性错误:类型对象没有属性

AttributeError:类型对象没有属性(*args 有问题?)

AttributeError: 类型对象“DirectView”没有属性“as_view”

DRF AttributeError类型对象'QuerySet'没有属性'nom'

类型对象“ Post”没有属性“ published” Django

AttributeError: 类型对象“DataFrame”没有属性“pd”

AttributeError: 类型对象“页面”没有属性“查询”

django类型对象Http404没有属性get

AttributeError类型的对象Person没有属性ID

类型对象没有属性“ get_or_create”

类型对象“ datetime.datetime”没有属性“ datetime”

类型对象“ datetime.datetime”没有属性“ datetime”

类型对象“PizzaMenu”没有属性“_default_manager”

熊猫类型对象“分类”没有属性“from_array”

AttributeError:类型对象“用户”没有属性“名称”

类型对象“ datetime.datetime”没有属性“ fromisoformat”

WxPython:类型对象“ Test”没有属性“ openReportButton”

错误:类型对象“键”没有属性“和弦”

Python-类型对象'str'没有属性'string'