我有一个表单,其中有一个文件上传字段,我还创建了一个变量,其中包含一组已批准的文件类型。我还将上传路由到特定文件夹中,如何使用以下变量...
FILE_TYPES = set(['txt', 'doc', 'docx', 'odt', 'pdf', 'rtf', 'text', 'wks', 'wps', 'wpd'])
为了将其整合到我的函数中...
if form.validate_on_submit():
flash('Form successfully submitted')
print "Form successfully submitted"
filename = secure_filename(form.file_upload.data.filename)
form.file_upload.data.save('uploads/' + filename)
return redirect('home')
else:
filename = None
print(form.errors)
return render_template('index.html',
title='Application Form',
form=form,
filename=filename)
使得只有这些文件类型可以被使用?