1
按DRF文件DRF ValidatorsDjango的REST框架 - 传递附加参数validate_foo
我的方法应该是这样
def validate_title(self, value):
"""
Check that the blog post is about Django.
"""
if 'django' not in value.lower():
raise serializers.ValidationError("Blog post is not about Django")
return value
我想一个额外的参数传递给validate_title
,所以它应该看起来像
这里id是我想调用序列化程序时要传递的一些值。
def validate_title(self, value, id):
"""
Check that the blog post is about Django.
"""
# Use <id> here
if 'django' not in value.lower():
raise serializers.ValidationError("Blog post is not about Django")
return value
我不能理解如何实现这个,有什么帮助吗?
ID值从哪里来? –
@DanielRoseman更新。 – ofnowhere
仍然不够清楚,无法获得帮助 – Linovia