I have a login page as login.py which renders login.html. On submit i want to redirect to mainpage.py which renders mainpage.html. But on submit click it just doesn't redirect. I get a page not found error. And the url remains the same
@app.route('/login',methods = ['GET','POST'])
def index():
try:
if request.method =='POST':
db_user = request.form['db_user']
db_pwd = request.form['db_pwd']
if (connect(db_user,db_pwd)==1):
return redirect("/mainpage", code=302)
else:
return render_template('login.html')
except Exception as e:
print(("error :", str(e)))
return render_template('login.html')
What should be mentioned in the redirect option? is it the html filename or py filename where the html gets rendered? I tried with html filename,py filename and the name in the @app.route. but without success
elseblock for db connect.redirect(url_for("your_function_name"))is better, but specifying an URL, like/mainpageshould be OK.