Django REST Framework serializer field required=false

后端 未结 6 535
无人共我
无人共我 2020-11-30 05:30

from the documentation:

read_only Set this to True to ensure that the field is used when serializing a representation, but is not used when updating

6条回答
  •  生来不讨喜
    2020-11-30 06:06

    In case somebody lands here with a similar issue, pay attention to the following attributes along with required:

    allow_blank:

    If set to True then the empty string should be considered a valid value.

    allow_null:

    Normally an error will be raised if None is passed to a serializer field.

    required:

    Normally an error will be raised if a field is not supplied during deserialization.

    I was straggling to figure out why I was getting a validation error with required=False where I had missed the allow_null attribute.

提交回复
热议问题