I've created the following serializer:
class KeywordSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Keyword
fields = ('my_field')
However, when I try to use it in a viewset, I get the following error:
The
fields
option must be a list or tuple or "__all__". Got str.
But the issue is, fields is a tuple. I've even tried setting it to all or a list, but I get the same error. The same error occurs regardless of the name of the field.
Would anyone know why this happens?
Yes, in Python ('my_field')
is a string. To make a single-element tuple you need a comma: ('my_field',)
.
Note this is nothing to do with DRF.
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