【发布时间】:2010-10-07 20:11:05
【问题描述】:
我有一个模型产品
它有两个字段大小和颜色
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 类型的对象”是您可以在 Python 文档中查找的内容。这是常数无。模型不是返回“NoneType”,而是返回 None,它是 NoneType 的对象。
标签: python django django-views