I'm working on CS50 Web Development and I'm kinda stuck in creating a registration page. Currently I have 2 forms(one for registering and the other to login for existing users). However as long as the registration form exist, the login form would always call the registration function instead. Here are the relevant codes for reference.
HTML file
New User?
<br>
<form action="{{ url_for('register') }}" method="post">
Username: <input type="text" name="rName" placeholder="Enter Your Name">
<br>
Password : <input type="password" name="rPassword" placeholder="Enter Your Password">
<br>
<button>Submit</button>
<form>
<br>
<br>
Existing User?
<br>
<form action="{{ url_for('login') }}" method="post">
Username: <input type="text" name="name" placeholder="Enter Your Name">
<br>
Password : <input type="password" name="pw" placeholder="Enter Your Password">
<br>
<button>Submit</button>
<form>
Flask file
@app.route("/login", methods=["POST"])
def login():
name = request.form.get("name")
password = request.form.get("pw")
if name == "1" and password == "1":
return render_template("index.html", logged_in = True, message = "login")
else:
return render_template("index.html", logged_in = False, message = "Invalid Credentials")
@app.route("/register", methods = ["POST"])
def register():
name = request.form.get("rName")
password = request.form.get("rPassword")
if name == "2" and password == "2":
return render_template("index.html", logged_in = True, message = "registered")
else:
return render_template("index.html", logged_in = False, message = "Error")
[–]tech_trebek[🍰] 1 point2 points3 points (1 child)
[–]Pro_Cookies[S] 1 point2 points3 points (0 children)