drf序列化器中的read_only和write_only选项
- 参考网址
https://www.cnblogs.com/jx-zzc/p/16522675.html
-
read_only: 表示只读,不能进行修改,也不会存入db(校验过后)
- 使用场景: id 字段
-
write_only: 只能写,不能读,可以存入db,但是返回响应时,不会包含此字段
- 使用场景: password_repeat 字段/sms_code
class RegisterSerializer(serializers.ModelSerializer):
password2 = serializers.CharField(write_only=True, label='重复密码')
sms_code = serializers.CharField(write_only=True, label='短信验证码')
allow = serializers.CharField(write_only=True, label='是否同意协议')
......
标签:知识点,serializers,收集,label,write,only,CharField,True,DRF
From: https://www.cnblogs.com/qinganning/p/16935230.html