Answer the question
In order to leave comments, you need to log in
Why does FileField.data return class 'str' and not class 'werkzeug.datastructures.FileStorage'?
To upload a custom image to the site (flask) use wtf forms in forms.py
class AddImage(FlaskForm):
image = FileField('Загрузите изображение(только .png)', validators=[DataRequired()])
print(type(form.image.data))
print(type(form.image))
form.image.data.save(image_name)
<class 'str'>
<class 'wtforms.fields.simple.FileField'>
и ошибку 'str' object has no attribute 'save'
Answer the question
In order to leave comments, you need to log in
You need to save the object of the orm model that you are using. The 'wtforms.fields.simple.FileField' object also most likely does not have a save method.
The logic should be like this:
profile = Profile()
image = form.image
profile.avatar = image
profile.save()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question