我有一个模型产品
它有两个字段大小和颜色
colours = models.CharField(blank=True, null=True, max_length=500)
size = models.CharField(blank=True, null=True, max_length=500)
在我看来
current_product = Product.objects.get(slug=title)
if len(current_product.size) != 0 :
current_product.size = current_product.size.split(",")
并获取此错误:
“NoneType”类型的对象没有len()
什么是NoneType?我如何测试它?
NoneType是Pythons空类型,意思是“nothing”,“undefined”。它只有一个值:“无”。创建新模型对象时,其属性通常初始化为“无”,可以通过比较来检查:
NoneType
是None
值所具有的类型。要将第二个片段更改为我可以用这个错误代码的例子来解释非类型错误:
s.remove()
不返回也称为NoneType的任何内容。正确的方法相关问题 更多 >
编程相关推荐