Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a login page
#21
@app.route("/login")
def login():
    password = request.form.get("password")
    username = request.form.get("username")
    db.execute('SELECT * FROM users WHERE username = :username AND password = :password', {"username":username, "password":password})
    account = db.fetchone()
    if account:
        return render_template("login.html")
    else:
        print("No!")
I changed it to this and now i'm getting an error that says:

AttributeError: 'scoped_session' object has no attribute 'fetchone'
#22
fetchone is a method specified in the DB API, rather than SQLAlchemy. I think I mentioned this before, but why are you trying to mix the two? If you intend to use SQLAlchemy, have you read the docs to see how to do queries?
#23
perhaps that's why i'm confused - i want to use sql alchemy. How should I use it?
#24
Read the documentation?
#25
@app.route("/login")
def login():
    password = request.form.get("password")
    username = request.form.get("username")
    usernamedata = db.execute("SELECT username FROM users WHERE username=:username", {"username":username}).fetchone()
	passworddata = db.execute("SELECT password FROM users WHERE username=:username", {"username":username}).fetchone()
    if username == usernamedata AND password == passworddata:
        return render_template("welcome.html")
    else:
        return render_template("login.html")
Ok now i have this and it's still giving me an error saying:

File "C:\school\project1\application.py", line 39
passworddata = db.execute("SELECT password FROM users WHERE username=:username",{"username":username}).fetchone()
^
TabError: inconsistent use of tabs and spaces in indentation

But I looked it up and fetchone() is used.
#26
Come on, at least try and understand the errors. You also shouldn't need to be doing two queries ti the database.

Where exactly were you reading about fetchone in Sqlalchemy?
#27
https://www.spiderposts.com/2019/07/04/f...th-python/

@app.route("/login", methods=["GET","POST"])
def login():
    password = request.form.get("password")
    username = request.form.get("username")
    usernamedata = db.execute("SELECT username FROM users WHERE username=:username", {"username":username}).fetchone()
    passworddata = db.execute("SELECT password FROM users WHERE username=:username", {"username":username}).fetchone()
    if username == usernamedata and password == passworddata:
        return render_template("welcome.html")
    else:
        return render_template("login.html")
@app.route("/home")
def home():   
    return render_template("home.html")
OK now I got this code and it's not giving me any errors. But it's not matching the username and password? It always goes to render login.html even when i type in a correct user and password.

I had it print out the username and it's correct.

I guess it's adding single quotes and a comma to the usernamedata and passworddata any idea how i can get rid of those?
#28
Please, stop and read the docs. fetchone() will not return string.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

#29
is there any one here who actually helps? Or are you guys just here to be condescending and to read the manual?

anyone can read the manual. what are you guys here for?

I'm starting to think I know more than you guys about Python. on here for days and nothing from u guys except "read the manual"
#30
You don't seem to show any effort in trying to work out what's wrong with your code, but just expect us to do the work for you. At least try to solve the problems, understand error messages, etc. and then ask for help when you're really stuck, showing us what you think the problem is. At the very least, you'll learn more that way than expecting to be spoon fed everything.


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Connect Login Page oguzcan 1 1,691 Apr-30-2020, 08:24 AM
Last Post: pyzyx3qwerty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020