表单验证不正确

Form validation incorrect

我有一个功能可以验证输入到我的表单中的文件类型。这是重要的部分...

if form.validate_on_submit():
        flash('Thanks %s, we will try to get back to your regarding you application as soon as possible.' % form.name.data) 
        print "Form successfully submitted"
        submit_name = form.file_upload.data.filename
        if '.' in submit_name and submit_name.rsplit('.', 1)[1] in FILE_TYPES:
            filename = secure_filename(submit_name)
            form.file_upload.data.save('uploads/' + filename)
            return redirect('home')
        else:
            flash('File %s is not an accepted format' % submit_name)

当没有文件提交表单时,我仍然收到闪现信息'file ... is not an accepted format'。但是,如果没有插入文件,我不想要一个闪现消息。有人知道怎么做吗?

需要添加:

elif submit_name == ""

然后是闪信

flash('File %s is not an accepted format' % submit_name)

并删除 else 语句以解决问题。