小船用蜡笔
bottle-cerberus的Python项目详细描述
Cerberus插件
Cerberus瓶子插件
安装
通过PIP:^{TT1}$
或克隆:git clone https://github.com/agalera/bottle-cerberus.git
示例:
frombottleimportget,install,runfrombottle_cerberusimportCerberusPlugin,SchemaclassExampleSchema(Schema):defschema(self):return{'ex':{'type':'integer'},'url':{'ex':{'coerce':int}}}classQuerySchema(Schema):defschema(self):return{'ex':{'coerce':int}}@get('/cerberus/<ex>',schemas={'body':ExampleSchema(),'query_string':QuerySchema())deftest_cerberus(ex):frombottleimportrequestprint("query_string",request.query['ex'],type(request.query['ex']))print("url",ex,type(ex))print("body",request.json.get('ex'),type(request.json.get('ex')))install(CerberusPlugin())run(host="0.0.0.0",port="9988")
模式
可选键
body:schema for request.json
url:url的架构(无查询字符串)
查询字符串:查询字符串的架构
模式
github架构:https://github.com/nicolaiarocci/cerberus文档架构: http://docs.python-cerberus.org/en/stable/