Python Forum

Full Version: Making a login page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
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")

            
            
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.
Error:
AttributeError AttributeError: 'tuple' object has no attribute 'keys'
That's the error I get. It doesn't give me a line.
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?
an online environment with flask

https://ibb.co/N1DHLKv

here is what it shows
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!
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.
(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!
what different code am i using?
(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.
Pages: 1 2 3 4 5