Ich baue versuche grad ein kleines Flaskprogramm zu schreiben. Jetzt stoße ich allerdings auch ein Problem, wo ich keine Lösung finde (vielleicht suche ich auch nur nach den falschen Begriffen :-/)
In einem Form haben ich ein FileField
Code: Alles auswählen
...
product_image = FileField('Produkt-Bild', validators=[FileAllowed(product_photos, 'Es sind nur Bilder erlaubt')])
...
Code: Alles auswählen
...
product_photo_path = product_photos.save(request.files['product_image'])
...
In einem anderen Form habe ich ein FileField in einer FieldList welches ich in ein FlaskForm einfüge, was auch funktioniert...sprich, es wird wenigstens schonmal im Browser gerendert

Code: Alles auswählen
class LampPower(Form):
...
...
photometric_data = FileField('LDTF- oder IES-Datei', validators=[FileAllowed(photometric_data, 'Es sind nur LDT- oder IES-Dateien erlaubt')])
Code: Alles auswählen
class NewProductStep3(FlaskForm):
lamp_power = FormField(LampPower, label='Lichtfarbe')
...
...
Code: Alles auswählen
product_photos = UploadSet('productphotos', IMAGES)
photometric_data = UploadSet('photometricdata', extensions=('ldt', 'ies'))

wenn ich den Namen des FileFields nehme (wie ich es bei dem funktionierenden Beispiel mache) bekomm ich folgende Fehlermeldung:
Code: Alles auswählen
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'photometric_data'
Wenn ich den Name nehme, der im HTML-Code steht kommt folgendes
Code: Alles auswählen
flask.debughelpers.DebugFilesKeyError: You tried to access the file "lamp_power-photometric_data" in the request.files dictionary but it does not exist. The mimetype for the request is "application/x-www-form-urlencoded" instead of "multipart/form-data" which means that no file contents were transmitted. To fix this error you should provide enctype="multipart/form-data" in your form.
Vielen Dank
Paddie