关于此WTForms功能,SO上还有一些未解决的问题。似乎没有文档涵盖此字段与FileField之间的唯一性。有没有人有一个有效的示例,说明如何上传多个文件并使用python访问它们?
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[validators.Length(min=4, max=25), validators.DataRequired()])
password = PasswordField('Password', [validators.DataRequired()])
packets = MultipleFileField('Upload filesT')
@app.route('/', methods=['GET', 'POST'])
def index():
form = forms.RegistrationForm()
if request.method == 'POST':
# Junk code for sake of exploration.
if form.packets.data:
print("files")
print(form.packets.data)
for file in form.packets.data:
print(file)
packet_filenames = secure_filename(form.packets.data)
else:
print("no files")