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 添加了如下的对象:
mysql数据库中的数据:
函数返回的是str,但是之前传的值是Decimal。
手工修改 __str__() 函数;
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)相关文章推荐
- django报错:TypeError: __str__returned non-string (type bytes)
- django Error during template rendering,TypeError: __str__ returned non-string (type int)
- Django rest framework 返回错误信息 __str__ returned non-string (type NoneType)
- Django rest framework __str__ returned non-string (type NoneType)
- TypeError: _str_returned non-string(type NoneType)
- Django rest framework:__str__ returned non-string (type NoneType) 真正原因
- Django rest framework __str__ returned non-string (type NoneType)
- Django models对象的select_related方法(减少查询次数)
- django 接受post请求json.dumps()的时候会引发TypeError: 'expected string or buffer'错误
- Django models对象的select_related方法(减少查询次数)
- __str__ returned non-string (type int)
- Django: TypeError: 'MediaDefiningClass' object is not iterable
- python smtplib TypeError: expected string or buffe
- mx:states包含mx:AddChild 在切换时提示错误"TypeError: Error #1009: 无法访问空对象引用的属性或方法"的解决方法
- django中报错TypeError: su() takes exactly 1 argument (2 given)的解决办法
- 面试题之String str = new String("abc"); 创建了几个对象
- 解决python中TypeError: not enough arguments for format string
- 查询脚本jquery出错:TypeError: rows is undefined
- 问题记录2:TypeError: write() argument must be str, not bytes
- TypeError: not all arguments converted during string formatting