Django查询models对象报错:TypeError: __str__ returned non-string (type decimal.Decimal)
来源:互联网 发布:艾媒咨询知乎 编辑:程序博客网 时间:2024/05/21 17:23
运行环境: 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__() 函数;
解决方式二:
类似的错误:
阅读全文
1 0
- Django查询models对象报错:TypeError: __str__ returned non-string (type decimal.Decimal)
- django Error during template rendering,TypeError: __str__ returned non-string (type int)
- Django rest framework __str__ returned non-string (type NoneType)
- django报错:TypeError: __str__returned non-string (type bytes)
- __str__ returned non-string (type int)
- Django rest framework 返回错误信息 __str__ returned non-string (type NoneType)
- TypeError: iter() returned non-iterator of type
- TypeError: iter() returned non-iterator of type
- TypeError: iter() returned non-iterator of type 'Fibs'
- Decimal
- Decimal
- Decimal
- Decimal
- decimal
- DECIMAL Data Type Characteristics
- DB2 DECIMAL data type
- 使用BigDecimal进行除法运算的时候报 Non-terminating decimal expansion; no exact representable decimal result
- Non-terminating decimal expansion; no exact representable decimal result
- 用openpyxl对比两个表格的数据,并把表格A 和表格B相同的数据填写到表格B
- Java的前期绑定和后期绑定
- Android C、C++与java端3DES互通
- 【C#】身份证识别(二):提取目标区域图像
- java九九乘法表
- Django查询models对象报错:TypeError: __str__ returned non-string (type decimal.Decimal)
- CI框架 insert_batch方法 返回-1,插入的数据不全
- C++学习笔记之MFC改变按钮颜色
- 找工作小结
- Java连接Sql Server 2008的简单数据库应用
- Spring Data Jpa+Hibernate 入门2
- 解决问题 “You don't have permission to access /index.html on this server.”
- jquery 选择器的使用
- log4j2示例