I am writing a python web application using the Flask framework, and the Flask-WTF, Flask-Login extensions with a postgreSQL db. Everytime I try to type an email or password into the input field the page refreshes and I can't type anything. How do I fix this? There just seem to be multiple GET requests being made to my view function.
HTML:
<!-- BODY OF THE LOGIN FORM -->
<div class = "login">
<form id = "loginform" action = "{{ url_for('login') }}" method = "post">
{% from "formhelpers.html" import render_field %}
{{render_field(form.email)}}
{{render_field(form.password)}}
<input type = "submit" class = "btn btn-default" value = "Log In">
</form>
</div>
PYTHON / FLASK view function:
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Send')
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if request.method == 'POST' and form.validate_on_submit():
#retrieve data from user
checkemail = form.email.data
checkpassword = form.password.data
#query database for user email
founduser = User.query.filter_by(email=checkemail).first()
#check password hashes if user is found by email
if founduser:
if hashpw(checkpassword, founduser.password.encode('utf-8')) == founduser.password:
return "SUCCESS: Logged In"
#incorrect password
else:
return "ERROR: Invalid Details"
#incorrect email address
else:
return "ERROR: User Doesn't Exist"
#passing an instance of our login form class to HTML for rendering
else:
return render_template('login.html', form=form)
Here is a screenshot of my terminal window. I have so many GET request being made as I try to type in the email or password fields. screenshot terminal window