简体   繁体   English

使用flask_wtf验证程序控制输入字段不起作用

[英]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.

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