from flask import Flask, url_for, render_template, redirect
app = Flask(__name__)
@app.route('/')
def hello_world():
...
...
#Don't know why you added an if Statement here
if True:
# 'lsuccess' is the name of your route function you are redirecting to
return redirect(url_for('lsuccess'))
#this statement is never reachable
else:
return render_template("error.html")
#You NEED A ROUTE FUNCTION named lsuccess, in this function, `render a template`
@app.route('/success')
def lsuccess():
return render_template('your_success.html')
if True won't have any effect on your code, since the condition will always be True and the else block will never run.
The if usernamedata is None condition is enough condition to make sure the user exists.
In the else statement, passworddata returns just one value e.g "password", using a for loop will iterate through each character e.g p, a and so on.
Remove the for loop, remove the if True and then remove the else block.
Final code should look like:
from flask import Flask, url_for, render_template, redirect
app = Flask(__name__)
@app.route('/')
def hello_world():
username = request.form.get("uname")
password = request.form.get("psw")
usernamedata = db.execute("SELECT username FROM register WHERE username=:username",
{"username": username}).fetchone()
passworddata = db.execute("SELECT password FROM register WHERE username=:username",
{"username": username}).fetchone()
if usernamedata is None:
return render_template("error.html")
else:
return redirect(url_for('lsuccess'))
@app.route('/success')
def lsuccess():
return render_template('your_success.html')
passworddatabtw?renderinga page, you areredirectingto a url.. In your views.py make sure the function that handles this url is actually rendering a page.rendera template