how to make POST method works for two different forms on same page with flask ?
Here's my code from main __int__.py file for flask / python
@app.route('/', methods=['GET', 'POST'])
@app.route('/login/', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['email'] != '1' or \
request.form['password'] != '1':
flash('Invalid Credentials')
else:
flash('You were successfully logged in')
return redirect(url_for('dashborad'))
return render_template('login.html', error=error)
@app.route('/', methods=['GET', 'POST'])
@app.route('/register/', methods=['GET', 'POST'])
def register():
try:
if request.method == 'POST':
email = request.form['email1']
name = request.form['name1']
password = request.form['password1']
cur, db = connection()
x = cur.execute(" SELECT * FROM users WHERE email = (%s)" ,[escape(email)])
if int(x) > 0:
flash ("email already used ")
return render_template ("register.html")
else:
cur.execute("INSERT INTO users (first_name, email, password) VALUES (%s, %s, %s);" ,(escape(name), escape(email), escape(password) ))
db.commit()
return render_template ("register.html")
right now python is reading POST method for first @app.route login form only
is there any easy way to get such line in python ?
if request.method == 'POST' for form 1
and
if request.method == 'POST' for form 2