0
我有以下串行:DRF:自定義字段驗證函數沒有被調用
class QuestionSerializer(serializers.ModelSerializer):
choices = ChoiceSerializer(many=True)
image = Base64ImageField(required=False)
def validate_image(self, value):
import ipdb
ipdb.set_trace()
# if value.get('fileArray', None):
# if value.get('dataURL', None):
# return value.get('dataURL')
# else:
# raise serializers.ValidationError("No file data present")
# else:
# return None
class Meta:
model = Question
fields = ('id', 'detail', 'image', 'true_false_answer', 'type', 'choices')
然後在視圖:
serializer = QuestionSerializer(data=data)
serializer.is_valid()
這給了我假 和:
serializer.errors
給出:
{'image': ['The submitted data was not a file. Check the encoding type on the form.']}
我發現的是validate_image永遠不會被調用。 可能是什麼問題?