Skip to content

Latest commit

 

History

History
42 lines (20 loc) · 928 Bytes

错误合集.md

File metadata and controls

42 lines (20 loc) · 928 Bytes
__str__ returned non-string (type tuple)

1️⃣ 创建好entry模型后,在admin管理界面,点击add的时候报错,

image-20231029195943868

image-20231029200051003

解决办法:在Topic模型中的__str__

##源代码

def __str__(self):
    return self.textself.date_added


##修改后
def __str__(self):
    return f"{self.text} - {self.date_added}"

在点击成功

image-20231029201859529

type object 'Topic' has no attribute 'object'

在视图文件中调用数据库查询将objects写成object了

    topics = Topic.objects.order_by('date_added')