python-SubmitField是否需要验证器?
作者:互联网
我是WTForms的新手.我有一个带有提交按钮的用户注册表格:
submit = SubmitField('Submit')
我要确保通过提交按钮而不是其他方式提交表单.在docs中指出
class wtforms.fields.SubmitField(default field arguments)
Represents an <input type="submit">. This allows checking if a given submit button has been pressed.
这就提出了一个问题:就我而言,我是否需要添加“必需”验证器?
例如,是否需要:
submit = SubmitField('Submit', [validators.Required()])
解决方法:
我想你是.查看源代码,没有什么是需要SubmitField的.
SubmitField实际上只是一个BooleanField:
class SubmitField(BooleanField):
"""
Represents an ``<input type="submit">``. This allows checking if a given
submit button has been pressed.
"""
widget = widgets.SubmitInput()
关联的窗口小部件只是具有类型=“ submit”的输入窗口小部件.它似乎还使用SubmitField的标签作为HTML中的文本.
class SubmitInput(Input):
"""
Renders a submit button.
The field's label is used as the text of the submit button instead of the
data on the field.
"""
input_type = 'submit'
def __call__(self, field, **kwargs):
kwargs.setdefault('value', field.label.text)
return super(SubmitInput, self).__call__(field, **kwargs)
它似乎并没有做更多的事情.
标签:wtforms,python 来源: https://codeday.me/bug/20191031/1978276.html