您的位置:首页 > 编程语言 > Go语言

Django查询models对象报错:TypeError: __str__ returned non-string (type decimal.Decimal)

2017-09-26 17:20 1321 查看
运行环境: python 3.6.1 Django 1.11.3
 modles.py 添加了如下的对象:
class ApplStockPrice(models.Model):
Date = models.CharField(max_length=20)
Open = models.DecimalField(max_digits=20,decimal_places=5)
High = models.DecimalField(max_digits=20,decimal_places=5)
Low = models.DecimalField(max_digits=20,decimal_places=5)
Close = models.DecimalField(max_digits=20,decimal_places=5)
Adj_Close = models.DecimalField(max_digits=20,decimal_places=6)
Volume = models.DecimalField(max_digits=20,decimal_places=2)

def __str__(self):
return self.Close


mysql数据库中的数据:



错误原因解析:



函数返回的是str,但是之前传的值是Decimal。

解决方式一:



手工修改 __str__() 函数;

解决方式二:

类似的错误:

TypeError: __str__ returned non-string (type tuple)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: