![]() |
Making a login page - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Making a login page (/thread-27559.html) |
Making a login page - card51shor - Jun-11-2020 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") RE: Making a login page - ndc85430 - Jun-11-2020 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. RE: Making a login page - card51shor - Jun-11-2020 That's the error I get. It doesn't give me a line.
RE: Making a login page - ndc85430 - Jun-11-2020 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? RE: Making a login page - card51shor - Jun-11-2020 an online environment with flask https://ibb.co/N1DHLKv here is what it shows RE: Making a login page - buran - Jun-11-2020 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! RE: Making a login page - card51shor - Jun-11-2020 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. RE: Making a login page - buran - Jun-11-2020 (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! RE: Making a login page - card51shor - Jun-11-2020 what different code am i using? RE: Making a login page - buran - Jun-11-2020 (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. |