I have a model Product
it has two fields size & colours among others
colours = models.CharField(blank=True, null=True, max_length=500)
size = models.CharField(blank=True, null=True, max_length=500)
In my view I have
current_product = Product.objects.get(slug=title)
if len(current_product.size) != 0 :
current_product.size = current_product.size.split(",")
and get this error:
object of type 'NoneType' has no len()
What is NoneType and how can I test for it?
NoneType is the type that the None value has. You want to change the second snippet to
if current_product.size: # This will evaluate as false if size is None or len(size) == 0.
blah blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With