[英]Using flask_wtf validators to control input filed not working
This is the code in forms.py
这是
forms.py
的代码
url = FileField(
label="File",
validators=[
DataRequired("Please upload your file")
],
description="File"
)
In HTML: 在HTML中:
{{ form.url }}
When I try to remove the required
attribute in views.py
by emptying validators
like this: form.url.validators = []
当我尝试通过清空
validators
来删除views.py
中的required
属性时: form.url.validators = []
It's not working, there's still a required
in the input filed, how to fix this 它不起作用,输入文件中仍然有
required
,如何解决此问题
In the list of validators there is the Optional()
validator which allows you to make an HTML field optional . 在验证器列表中,有
Optional()
验证器,它使您可以将HTML字段设置为optional 。 Here's how to use it: 使用方法如下:
url = FileField(label="File", validators=[Optional()], description="File")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.