简体   繁体   English

使用flask-restful限制允许的参数

[英]restrict allowed arguments using flask-restful

flask-restful has a useful request parser with which one can declare required and optional arguments in various request locations such as the query string or in json content. flask-restful有一个有用的请求解析器,通过它可以在各种请求位置(例如查询字符串或json内容)中声明必需和可选参数。 Arguments that are not declared are ignored by the parser. 解析器将忽略未声明的参数。

Is there a way to restrict the arguments, so that if a request contains undecalred arguments the server would respond with a 500 Bad Request instead of ignoring them? 有没有一种方法来限制参数,以便如果请求包含未声明的参数,则服务器将以500错误的请求响应而不是忽略它们?

是的,如果您签出文档,那么您会看到可以将strict = True参数传递给parse_args(),它将执行您想要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM