我尝试添加架构验证,因为它在官方檐口文档中描述,并通过像 service_name.post(schema=SomeSchemaClass) 这样的装饰器来做到这一点,但它不起作用
import colander
class TrackSchema(colander.MappingSchema):
genre = colander.SchemaNode(colander.String(), location="body", type='str')
@track.post(schema=TrackSchema)
def create_track(request):
...
我得到错误
"status": "error", "errors": [{"location": "body", "name": null, "description": "Expecting value: line 1 column 2 (char 1)"}, {"location": "body", "name": "genre", "description": "genre is missing"}]}
我尝试了不同类型的位置参数,如查询字符串和标题,但我得到了同样的错误。