I'm learning Python and using Flask to develop an application and one of the features is that a user can upload a profile picture and that image should be saved in the database.
I have a form where the user can upload a file, like this:
<form action="/myprofile" method="post" enctype="multipart/form-data">
<div class="form-group">
<input class="form-control" name="picture" placeholder="Picture" type="file">
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
And then, in the application.py file I'm handling it like this:
@app.route("/myprofile", methods=["GET", "POST"])
@login_required
def myprofile():
if request.method == "POST":
db.execute("UPDATE users SET role = :role, picture = :picture, linkedin = :linkedin WHERE id = :user_id", role = request.form.get("role"), picture = request.files("picture"), linkedin = request.form.get("linkedin"), user_id = session["user_id"])
return render_template("home.html")
else:
return render_template("myprofile.html")
This is returning an Internal Server Error. Does anyone have any idea why?
Thanks for your time!