Flask SQLAlchemy orderby


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()
            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!

Not sure about this @Leon145.
Have you checked to delete the cache, force reload, and all of that?
Also if you are running the server in production mode, the property TEMPLATES_AUTO_RELOAD is set to None by default. It’s only True when on development mode. This can lead to strange behaviours. Again, not sure.