-1

So I am doing a side project for my self, trying to learn.

Framework: Flask pandas csv raspberry 4

Goal: to import a csv or xlsx file into a html form and print it out on the html page.

this is what I have so far:

when I import the file, I get the following. TypeError: 'ImmutableMultiDict' object is not callable

Python Code:

def read_csv(filein):
  filein = pd.read_excel('file.xlxs')
  print(filein)

@app.route('/import_form', methods=['POST', 'GET'])
def import_form():
    if request.method == "POST":
        filein = request.files()
        print(filein)
        #return redirect('/thankyou.html')
    else:
        return 'something is wrong'
        

HMTL Code:

 <form action="import_form" method="post" class="reveal-content">
                  <div class="row">
                    <div class="col-md-7">
                      <div class="form-group">
                        <input name="filename" type="file"  accept=".csv, .xlsx" class="form-control" id="filename" placeholder="filename" required >
                      </div>
                      </div>
                      <button type="submit" class="btn btn-default btn-lg">Send</button>
                    </div>
                </form>
Steve0-90
  • 1
  • 1

1 Answers1

0

The error is because you can't use .files() files is not a function, so it isn't call able.

The right way to do that what you want is :

request.files["filename"]

You may visit here for more information.

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • Additionally I believe this is typo here while asking question but you are doing wrong here also. `action="import_form` you should have done `action="/import_form` – imxitiz Aug 06 '21 at 16:31
  • and the answer you gave did not help :( – Steve0-90 Aug 07 '21 at 00:43
  • then why you are thanking everyone? Are you getting same error after editing as I said? @Steve0-90 – imxitiz Aug 07 '21 at 00:44
  • for trying to provide help. just being nice. and no I have made some changes to the code, now I'm getting template not found. I've been at this for like 5 hours. I tried to follow a video on YT but it was no help. I'm not giving up. I will figure this out. – Steve0-90 Aug 07 '21 at 00:45