Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

462
Views
Flask-WTForm FileField returns None instead of the file uploaded

I am trying to upload a picture using Flask-WTForm's FileField. But even though I upload a picture, it can't detect it.

The form is created as:

class User_settings_profile_picture_form(FlaskForm):
    picture = FileField('Update profile picture', validators=[DataRequired(), FileAllowed(['jpg', 'png', 'jpeg', 'gif'])])
    submit = SubmitField('Update')

The route where the form is used is like:

profile_pic_form = User_settings_profile_picture_form()
.
.
.
if profile_pic_form.validate_on_submit():
    if profile_pic_form.picture.data:
        ...
else:
    #for debugging purposes
    print("Is valid: " + profile_pic_form.validate())
    print("Errors: " + profile_pic_form.errors)
    print("Request files: " + request.files)

The print statements are for debugging purposes and in the console it is like:

Is valid: False
Errors: {'picture': ['This field is required.']}
Request files: ImmutableMultiDict([])

The html looks like:

<form method="POST" action="">
    {{ profile_pic_form.hidden_tag() }}
    <div class="mb-3">
        <h3>Profile Picture</h3>
        {{ profile_pic_form.picture(class="form-control-file", placeholder="Enter new Bio") }}
        {{ profile_pic_form.submit(class="mt-3 btn btn-primary mb-5") }}
    </div>
</form>

If I print the profile_pic_form.picture.data, it gives me None.

Does anyone know why this is happening. I looked through SO, but did not find a solution for this specific case.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem was in the html. It should be:

<form method="POST" action="" enctype="multipart/form-data">

Instead of just:

<form method="POST" action="">

Edit: Read the documentation to understand better.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!