Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a login page
#1
Hey guys I'm working on a log in page and I'm getting an error that it's a tuple value but I am just trying to get one value. Does anyone see the error in my code?
Thanks!

import os
import psycopg2


from flask import Flask, session, render_template, request
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker


app = Flask(__name__)

# Check for environment variable
if not os.getenv("DATABASE_URL"):
    raise RuntimeError("DATABASE_URL is not set")

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')

# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))


@app.route("/welcome")
def index():
    return render_template("welcome.html")

@app.route("/login")
def login():
    password = request.form.get("password")
    username = request.form.get("username")
    db.execute('SELECT * FROM users WHERE username = %s AND password = %s', (username, password,))
    account = db.fetchone()
    if account:
        return render_template("login.html")
    else:
        print "No!"

@app.route("/home")
def home():   
    return render_template("home.html")




            
          
@app.route("/register", methods=["GET", "POST"])
def register():
    
    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        password = request.form.get("password")
        username = request.form.get("username")
        session.clear()
        db.execute("INSERT INTO users (username, password) VALUES (:username, :password)", {"username":username, "password":password})
        db.commit()
        return render_template("login.html")

            
            
#2
It would really help if you posted the traceback to show what exactly the problem is and on which line it occurs. There's no point making us guess.
#3
Error:
AttributeError AttributeError: 'tuple' object has no attribute 'keys'
That's the error I get. It doesn't give me a line.
#4
Where are you running this? Python tracebacks usually give you the entire call stack. Are you running your program in some online environment or something that is literally only giving you that line?
#5
an online environment with flask

https://ibb.co/N1DHLKv

here is what it shows
#6
Please, stop posting images. You have been advised multiple times to stop. Copy paste code, traceback, output, etc. and use proper BBCode tags.
The traceback from image show that you are using different code than the one you post here. AGAIN!
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

#7
is there anyone who can actually help me?

Seems like I just get scolded for posting things in the wrong place.

Does anyone have a solution? I don't know how to paste all different kinds of codes.
#8
(Jun-11-2020, 05:54 AM)card51shor Wrote: Seems like I just get scolded for posting things in the wrong place.
You are not schooled. You are asked to follow forum rules. Which you do not. And by not follwoing them you make it more difficult for people to help you.
(Jun-11-2020, 05:54 AM)card51shor Wrote: The traceback from image show that you are using different code than the one you post here. AGAIN!
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

#9
what different code am i using?
#10
(Jun-11-2020, 05:54 AM)card51shor Wrote: Does anyone have a solution? I don't know how to paste all different kinds of codes.
You have been advised multiple times how to do so
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
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



Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Connect Login Page oguzcan 1 1,694 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