I'm trying to create a very basic login. To do this I need to store the "id" that matches a "username" in my "users" table.
It will only give me back a list though no matter what I've tried.
I'm following an online course and I can't use most SQLAlchemy shortcuts--just good old fashioned SQL commands. I'm using Python 3 and Flask to build it out.
@app.route("/login", methods=["GET","POST"])
def login():
if request.method == "GET":
return render_template("login.html")
if request.method == "POST":
#find user in users table
username = request.form["username"]
rows = db.execute("SELECT id FROM users WHERE username=:username",{"username": username}).fetchall()
session["user_id"] = rows.id
return render_template("success.html", rows=rows)
if the id is 1 it literally returns: '(1,)'
fetchval()instead offetchall(). (fetchval()is a pyodbc extension to the DB API.)