作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的UploadForm类:
from app import app
from flask_wtf.file import FileRequired, FileAllowed
from wtforms.fields import MultipleFileField
from wtforms.validators import InputRequired,DataRequired
class UploadForm(FlaskForm):
.
.
.
roomImage = MultipleFileField('Room',validators=[FileAllowed(['jpg', 'png'], 'Image only!'), FileRequired('File was empty!')] )
.
.
.#there are other fields here which are not relevant to the problem at hand
HTML模板
{% extends "base.html" %}
{% block content %}
<h1>Upload Your Images</h1>
<form action="/" enctype="multipart/form-data" method="post" >
{{ form.csrf_token }}
Room<br />
{{form.roomImage()}}
.
.
. <MORE THINGS THAT I HAVE EDITED OUT>
{{form.submit()}}
<br/>
{% if form.errors %}
{{ form.errors }}
{% endif %}
</form>
{% endblock %}
hosts.py以运行检查以进行验证
def upload_image():#NEEDS HEAVY FIXING
"""home page to return the web page to upload documents"""
form = UploadForm()
if form.validate_on_submit():
使用VS的调试工具,我发现form.validate_on_submit()无法正常工作,并且始终无法通过验证,并且我在html页面上收到了此错误。
{'roomImage': ['File was empty!']}
最佳答案
这对我有用(在GitHub上“在两线之间”找到):
multi_file = MultipleFileField("Upload File(s)", validators=[DataRequired()])
FileAllowed(["xml", "jpg"])
form.validate()
和
form.validate_on_submit()
返回True,但是当您不传递任何文件时,通过删除
required=""
<input id="multi_file" multiple="" name="multi_file" required="" type="file">
关于python - 在我的表单中使用MultipleFileField()时,FileRequiredValidator()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59734277/
我的UploadForm类: from app import app from flask_wtf.file import FileRequired, FileAllowed
我是一名优秀的程序员,十分优秀!