我有一个字典字段,其中没有值,该值应该来自 data dict()
data = {'name': 'Robot', 'title': 'This is title'} #missing one required field 'text'
fields = {'name': '', 'title': '', 'text': ''}
现在,我将数据发送到字段dict()。如果数据具有所有键作为字段,则字段dict()将填充有数据值。或者,如果数据缺少一个或多个字段,则会将“必需”作为值添加到字段dict()中的键。
根据上面的代码,字段应返回:
fields = {
'name': 'Robot',
'title': 'This is title',
'text': 'required'
}
如何有效地完成此任务?有人可以帮我吗?