Hi,
I am trying to order a database on the click of a button on an HTML page. The database itself is being sorted but I am unable to display the sorted data on the HTML page.
@app.route("/library", methods=["POST", "GET"])
def library():
if request.method == "POST":
if request.form.get("home_page") == "Return to home page":
flash('Returned to home page!')
return redirect(url_for("home"))
elif request.form.get("sort_date") == "Sort library by most recent date":
ordered = words.query.order_by(asc(words.date_uploaded)).all()
print(ordered)
return render_template("library.html", values=ordered)
return render_template("library.html", values=words.query.all())
Here is my sorting function which works (the print line to console) but does not update the HTML page. I’ve tried using db.session.commit() but that creates an error (commit() takes 1 positional argument but 2 were given). Any help would be appreciated!