让我们检查烧瓶参数
flask-value-checker的Python项目详细描述
烧瓶值检查:mag_right:
想象一下web表单检查,但是现在想象一下它是简单和舒适的
示例用法
fromflask_value_checkerimportInvigilatorfromflaskimportFlask,requestinvigilator=Invigilator()@app.route('/abc',methods=['POST'])@invigilator.check('POST',''' username : str/lenlim(5, 15) password : str/lenlim(8, inf) stayLoggedIn : str/accept(['on'])/optional ''')defabc():stay_logged_in=request.form.get('stayLoggedIn','off')returnf'hi {request.form['username']}, stay logged in: {stay_logged_in}'app.run()
示例默认错误
注意:此错误可能be customized
^{pr2}$功能文档:带装饰性_封面的笔记本电脑::笔记本::封闭式_书籍::蓝色书籍:
Invigilator(err_function=None)
- Type : ^{
} or ^{ } - Description : the function that displays the final error to the webpage, must be written the the way a standard flask function is written, (although you may wanna check out Flask.Response,并返回它而不是像
(error, 400)
这样的元组) - Example
defcustom_error_shower(errors):returnResponse(json.dumps({"errors":errors,}),status=400,mimetype="application/json")
你知道吗监考。检查(http方法,checker_str)
http方法:
- Type:
str
或{} - Description:要检查的HTTP方法
NOTE:如果方法中不存在要检查的http方法,则将正常调用修饰函数,并且不会执行任何检查
- 示例:
'GET'
,'POST'
,['GET', 'POST']
字段名属性文档
所有top属性(str、int、float)都不应该有任何参数
Note:应首先放置顶部属性,然后放置其子属性 应放置
str
lenlim(最小值,最大值)
字段字符串的最小和最大长度
- min:
int
或值inf
,即可接受的最小字符串长度 - ^{{{str}或最大值{1}接受
可选
属性是可选的吗?在
接受(接受的值)
使用字段名时可以接受的值
- 接受的值:
list of strings
,参数的可接受值
int和float
int指定数字必须是整数
float指定它可以是十进制的
两个属性具有相同的子属性
lim(最小值,最大值)
数值可以介于
- min:
float
或值inf
,最小可接受的数值 - max:
float
或值inf
(请参见bigger-full-example),即可接受的最大数值
可选
属性是可选的吗?在
检查结构
- Type:
str
- Description:以指定格式See Here编写的表单属性及其限制
导语:金属:
写入参数:
- 不同的参数用换行符隔开
- 参数及其规则由
:
分隔 - 规则条件用
/
分隔 - 第一个条件应该是所需值的类型,
str
,int
或{} - 条件参数放在括号中
()
示例:
score : float/lim(0, 11.5)/optional
更大的完整示例
@app.route('/abc')@invigilator.check('POST',''' firstName : str/lenlim(1, 15) middleName : str/optional lastName : str/optional stayLoggedIn : str/accept(['on'])/optional email : str password : str/lenlim(8, inf) phone : str/lenlim(8, 15) # number will have to be an Int, # but it'll have to be greater than # 18, not including 18 age : int/lim(18.9, inf) score : float/lim(0, 10) # can be a decimal value ''')defabc():some_content
开发文档
- 代码样式:黑色
- 文档样式:numpydoc
- HTTP向Numpydoc返回extra,这与Return类似,但表示如下
'''HTTP-Returns------------400 on failure, the response will be similar to, { "error": { "code": "MALFORMED_OR_MISSING_PARAMETERS", "message": "one or more fields we're either missing or malformed", "fields": { "email" : "missing parameter, parameter is required", "firstName" : "name has to be under 15 characters", "age" : "parameter has to be of type 'int'" ... } } }* or whatever the original function returns *'''
即
<return code>
<details>
<return message>
- 项目
标签: