Trying to upload a csv file, open it and then iterate through the rows to insert each field in to the postgres database, I have 2 (identified so far) problems with this. I am using Flask not Django.
I get an indentation error, although I cannot for the life of me see where. RESOLVED
The heroku logs provide no other feedback so I am unsure even if the file is correctly opened and read.
The csv file is:
first_name last_name email etc. # in all 8 columns
John Smith [email protected]
and the python code is:
@app.route("/uploadcsv", methods=['POST'])
def uploadcsv():
csvfile = request.files['file']
with open(csvfile):
reader = csv.DictReader(csvfile)
for row in reader:
firstname = row['first_name']
query = Prospect(first_name=firstname)
db.session.add(query)
db.session.commit()
return "OK"
So, there are 2 questions:
what is the indentation problem? RESOLVED
Is the code correct for uploading, opening and insertion?