gpt4 book ai didi

python - 如何在 Eve 中设置默认值?

转载 作者:太空宇宙 更新时间:2023-11-04 03:35:34 25 4
gpt4 key购买 nike

在 Python REST API 框架 Eve 中,是否可以在模式中设置默认值?如何?

最佳答案

是的,这是可能的,只需使用 default 模式设置。来自documentation :

The default value for the field. When serving POST and PUT requests, missing fields will be assigned the configured default values.

It works also for types dict and list. The latter is restricted and works only for lists with schemas (list with a random number of elements and each element being a dict)

schema = {
# Simple default
'title': {
'type': 'string',
'default': 'M.'
},
# Default in a dict
'others': {
'type': 'dict',
'schema': {
'code': {
'type': 'integer',
'default': 100
}
}
},
# Default in a list of dicts
'mylist': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'name': {'type': 'string'},
'customer': {
'type': 'boolean',
'default': False
}
}
}
}
}

关于python - 如何在 Eve 中设置默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29278438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com