我有一個模型產品Django模塊返回NoneType
它有兩個字段的大小等等
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的一個對象。 – 2009-02-16 11:17:36